From b43b3371970487059a532aeaf34c3973d023f1fb Mon Sep 17 00:00:00 2001 From: Jakub Jirutka Date: Fri, 6 Mar 2020 22:19:43 +0100 Subject: [PATCH] don't apply passthrough substitution inside stem macros I just moved processing of the stem substitutions before processing of the passthrough substitutions. It seems that it works well and the side effects of this change are acceptable, i.e. they will probably affect much less users than the current undesirable behaviour of + signs inside the stem macros. Fixes #3409 --- lib/asciidoctor/substitutors.rb | 33 ++++++++++++++++----------------- test/substitutions_test.rb | 10 +--------- 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/lib/asciidoctor/substitutors.rb b/lib/asciidoctor/substitutors.rb index 28884f5823..64876d9e90 100644 --- a/lib/asciidoctor/substitutors.rb +++ b/lib/asciidoctor/substitutors.rb @@ -1053,6 +1053,22 @@ def extract_passthroughs text %(#{preceding || ''}#{PASS_START}#{passthru_key}#{PASS_END}) end if (text.include? '++') || (text.include? '$$') || (text.include? 'ss:') + text = text.gsub InlineStemMacroRx do + # honor the escape + next $&.slice 1, $&.length if $&.start_with? RS + + if (type = $1.to_sym) == :stem + type = STEM_TYPE_ALIASES[@document.attributes['stem']].to_sym + end + subs = $2 + content = normalize_text $3, nil, true + # NOTE drop enclosing $ signs around latexmath for backwards compatibility with AsciiDoc Python + content = content.slice 1, content.length - 2 if type == :latexmath && (content.start_with? '$') && (content.end_with? '$') + subs = subs ? (resolve_pass_subs subs) : ((@document.basebackend? 'html') ? BASIC_SUBS : nil) + passthrus[passthru_key = passthrus.size] = { text: content, subs: subs, type: type } + %(#{PASS_START}#{passthru_key}#{PASS_END}) + end if (text.include? ':') && ((text.include? 'stem:') || (text.include? 'math:')) + pass_inline_char1, pass_inline_char2, pass_inline_rx = InlinePassRx[compat_mode] text = text.gsub pass_inline_rx do preceding = $1 @@ -1102,23 +1118,6 @@ def extract_passthroughs text %(#{preceding}#{PASS_START}#{passthru_key}#{PASS_END}) end if (text.include? pass_inline_char1) || (pass_inline_char2 && (text.include? pass_inline_char2)) - # NOTE we need to do the stem in a subsequent step to allow it to be escaped by the former - text = text.gsub InlineStemMacroRx do - # honor the escape - next $&.slice 1, $&.length if $&.start_with? RS - - if (type = $1.to_sym) == :stem - type = STEM_TYPE_ALIASES[@document.attributes['stem']].to_sym - end - subs = $2 - content = normalize_text $3, nil, true - # NOTE drop enclosing $ signs around latexmath for backwards compatibility with AsciiDoc Python - content = content.slice 1, content.length - 2 if type == :latexmath && (content.start_with? '$') && (content.end_with? '$') - subs = subs ? (resolve_pass_subs subs) : ((@document.basebackend? 'html') ? BASIC_SUBS : nil) - passthrus[passthru_key = passthrus.size] = { text: content, subs: subs, type: type } - %(#{PASS_START}#{passthru_key}#{PASS_END}) - end if (text.include? ':') && ((text.include? 'stem:') || (text.include? 'math:')) - text end diff --git a/test/substitutions_test.rb b/test/substitutions_test.rb index 3f4eddf02c..49dc5c71f7 100644 --- a/test/substitutions_test.rb +++ b/test/substitutions_test.rb @@ -1955,15 +1955,7 @@ end test 'should passthrough math macro inside another passthrough' do - input = 'the text `asciimath:[x = y]` should be passed through as +literal+ text' - para = block_from_string input, attributes: { 'compat-mode' => '' } - assert_equal 'the text asciimath:[x = y] should be passed through as literal text', para.content - - input = 'the text [x-]`asciimath:[x = y]` should be passed through as `literal` text' - para = block_from_string input - assert_equal 'the text asciimath:[x = y] should be passed through as literal text', para.content - - input = 'the text `+asciimath:[x = y]+` should be passed through as `literal` text' + input = 'the text `++asciimath:[x = y]++` should be passed through as `literal` text' para = block_from_string input assert_equal 'the text asciimath:[x = y] should be passed through as literal text', para.content end