diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/asciidoctor/rx.rb | 18 | ||||
| -rw-r--r-- | lib/asciidoctor/substitutors.rb | 39 |
2 files changed, 18 insertions, 39 deletions
diff --git a/lib/asciidoctor/rx.rb b/lib/asciidoctor/rx.rb index 39fb0fd3..2fabe0dc 100644 --- a/lib/asciidoctor/rx.rb +++ b/lib/asciidoctor/rx.rb @@ -569,23 +569,17 @@ module Asciidoctor # Examples # # +text+ - # `text` (compat) + # [x-]+text+ + # [x-]`text` + # `text` (compat only) + # [role]`text` (compat only) # # NOTE we always capture the attributes so we know when to use compatible (i.e., legacy) behavior InlinePassRx = { - false => ['+', '`', /(^|[^#{CC_WORD};:])(?:#{QuoteAttributeListRxt})?(\\?(\+|`)(\S|\S#{CC_ALL}*?\S)\4)(?!#{CG_WORD})/m], - true => ['`', nil, /(^|[^`#{CC_WORD}])(?:#{QuoteAttributeListRxt})?(\\?(`)([^`\s]|[^`\s]#{CC_ALL}*?\S)\4)(?![`#{CC_WORD}])/m], + false => ['+', '-]', /((?:^|[^#{CC_WORD};:\\])(?=(\[)|\+)|\\(?=\[)|(?=\\\+))(?:\2(x-|[^\[\]]+ x-)\]|(?:#{QuoteAttributeListRxt})?(?=(\\)?\+))(\5?(\+|`)(\S|\S#{CC_ALL}*?\S)\7)(?!#{CG_WORD})/m], + true => ['`', nil, /(^|[^`#{CC_WORD}])(?:(\Z)()|#{QuoteAttributeListRxt}(?=(\\))?)?(\5?(`)([^`\s]|[^`\s]#{CC_ALL}*?\S)\7)(?![`#{CC_WORD}])/m], } - # Matches an inline plus passthrough spanning multiple lines, but only when it occurs directly - # inside constrained monospaced formatting in non-compat mode. - # - # Examples - # - # +text+ - # - SinglePlusInlinePassRx = /^(\\)?\+(\S|\S#{CC_ALL}*?\S)\+$/m - # Matches several variants of the passthrough inline macro, which may span multiple lines. # # Examples diff --git a/lib/asciidoctor/substitutors.rb b/lib/asciidoctor/substitutors.rb index af850790..d88e0d74 100644 --- a/lib/asciidoctor/substitutors.rb +++ b/lib/asciidoctor/substitutors.rb @@ -1065,10 +1065,11 @@ module Substitutors pass_inline_char1, pass_inline_char2, pass_inline_rx = InlinePassRx[compat_mode] text = text.gsub pass_inline_rx do preceding = $1 - attrlist = $2 - escape_mark = RS if (quoted_text = $3).start_with? RS - backtick_mark = $4 == '`' - content = $5 + attrlist = $4 || $3 + escaped = true if $5 + quoted_text = $6 + format_mark = $7 + content = $8 if compat_mode old_behavior = true @@ -1077,32 +1078,30 @@ module Substitutors end if attrlist - if backtick_mark && !old_behavior - next extract_inner_passthrough content, %(#{preceding}[#{attrlist}]#{escape_mark}) - elsif escape_mark + if escaped # honor the escape of the formatting mark - next %(#{preceding}[#{attrlist}]#{old_behavior_forced && backtick_mark ? quoted_text : (quoted_text.slice 1, quoted_text.length)}) + next %(#{preceding}[#{attrlist}]#{quoted_text.slice 1, quoted_text.length}) elsif preceding == RS # honor the escape of the attributes - next %(#{preceding}[#{attrlist}]#{quoted_text}) if old_behavior_forced && backtick_mark + next %(#{preceding}[#{attrlist}]#{quoted_text}) if old_behavior_forced && format_mark == '`' preceding = %([#{attrlist}]) elsif old_behavior_forced attributes = attrlist == 'x-' ? {} : (parse_quoted_text_attributes attrlist.slice 0, attrlist.length - 3) else attributes = parse_quoted_text_attributes attrlist end - elsif backtick_mark && !old_behavior - next extract_inner_passthrough content, %(#{preceding}#{escape_mark}) - elsif escape_mark + elsif escaped # honor the escape of the formatting mark next %(#{preceding}#{quoted_text.slice 1, quoted_text.length}) + elsif compat_mode && preceding == RS + next quoted_text end if compat_mode passthrus[passthru_key = passthrus.size] = { text: content, subs: BASIC_SUBS, attributes: attributes, type: :monospaced } elsif attributes if old_behavior - subs = backtick_mark ? BASIC_SUBS : NORMAL_SUBS + subs = format_mark == '`' ? BASIC_SUBS : NORMAL_SUBS passthrus[passthru_key = passthrus.size] = { text: content, subs: subs, attributes: attributes, type: :monospaced } else passthrus[passthru_key = passthrus.size] = { text: content, subs: BASIC_SUBS, attributes: attributes, type: :unquoted } @@ -1400,20 +1399,6 @@ module Substitutors end.join LF) end - # Internal: Extract nested single-plus passthrough; otherwise return unprocessed - def extract_inner_passthrough text, pre - if (text.end_with? '+') && (text.start_with? '+', '\+') && SinglePlusInlinePassRx =~ text - if $1 - %(#{pre}`+#{$2}+`) - else - @passthroughs[passthru_key = @passthroughs.size] = { text: $2, subs: BASIC_SUBS } - %(#{pre}`#{PASS_START}#{passthru_key}#{PASS_END}`) - end - else - %(#{pre}`#{text}`) - end - end - # Internal: Convert a quoted text region # # match - The MatchData for the quoted text region |
