summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2017-05-07 17:45:57 -0600
committerDan Allen <dan.j.allen@gmail.com>2017-05-07 17:45:57 -0600
commit83aaa4dbe6c04c251b1ca2ca892ac001563e3545 (patch)
tree0f1f55e12582e93be6cff3cb1799e9327b82f604
parentd16b42fbecc9b5141dd40c4eeb2d5af896e9c128 (diff)
process pass inline macro with empty text; invert extract logic
-rw-r--r--lib/asciidoctor.rb2
-rw-r--r--lib/asciidoctor/substitutors.rb16
-rw-r--r--test/substitutions_test.rb7
3 files changed, 16 insertions, 9 deletions
diff --git a/lib/asciidoctor.rb b/lib/asciidoctor.rb
index b4e0f7db..e4c3cbe7 100644
--- a/lib/asciidoctor.rb
+++ b/lib/asciidoctor.rb
@@ -971,7 +971,7 @@ module Asciidoctor
# $$text$$
# pass:quotes[text]
#
- PassInlineMacroRx = /(?:(?:(\\?)\[([^\]]+?)\])?(\\{0,2})(\+{2,3}|\$\$)(#{CC_ALL}*?)\4|(\\?)pass:([a-z,]*)\[(#{CC_ALL}*?[^\\])\])/m
+ PassInlineMacroRx = /(?:(?:(\\?)\[([^\]]+?)\])?(\\{0,2})(\+{2,3}|\$\$)(#{CC_ALL}*?)\4|(\\?)pass:([a-z,]*)\[(|#{CC_ALL}*?[^\\])\])/m
# Matches an xref (i.e., cross-reference) inline macro, which may span multiple lines.
#
diff --git a/lib/asciidoctor/substitutors.rb b/lib/asciidoctor/substitutors.rb
index 831ba7bf..ca505d14 100644
--- a/lib/asciidoctor/substitutors.rb
+++ b/lib/asciidoctor/substitutors.rb
@@ -167,14 +167,7 @@ module Substitutors
m = $~
preceding = nil
- if (boundary = m[4]).nil_or_empty? # pass:[]
- if m[6] == '\\'
- # NOTE we don't look for nested pass:[] macros
- next m[0][1..-1]
- end
-
- @passthroughs[pass_key = @passthroughs.size] = {:text => (unescape_brackets m[8]), :subs => (m[7].nil_or_empty? ? [] : (resolve_pass_subs m[7]))}
- else # $$, ++ or +++
+ if (boundary = m[4]) # $$, ++, or +++
# skip ++ in compat mode, handled as normal quoted text
if compat_mode && boundary == '++'
next m[2].nil_or_empty? ?
@@ -217,6 +210,13 @@ module Substitutors
else
@passthroughs[pass_key] = {:text => content, :subs => subs}
end
+ else # pass:[]
+ if m[6] == '\\'
+ # NOTE we don't look for nested pass:[] macros
+ next m[0][1..-1]
+ end
+
+ @passthroughs[pass_key = @passthroughs.size] = {:text => (unescape_brackets m[8]), :subs => (m[7].nil_or_empty? ? [] : (resolve_pass_subs m[7]))}
end
%(#{preceding}#{PASS_START}#{pass_key}#{PASS_END})
diff --git a/test/substitutions_test.rb b/test/substitutions_test.rb
index 1e98670d..34e6f076 100644
--- a/test/substitutions_test.rb
+++ b/test/substitutions_test.rb
@@ -1360,6 +1360,13 @@ EOS
assert_equal '<strong><html5></strong>', result
end
+ test 'should allow content of inline pass macro to be empty' do
+ para = block_from_string 'pass:[]'
+ result = para.extract_passthroughs para.source
+ assert_equal 1, para.passthroughs.size
+ assert_equal '', para.restore_passthroughs(result)
+ end
+
# NOTE placeholder is surrounded by text to prevent reader from stripping trailing boundary char (unique to test scenario)
test 'restore inline passthroughs without subs' do
para = block_from_string("some #{Asciidoctor::Substitutors::PASS_START}" + '0' + "#{Asciidoctor::Substitutors::PASS_END} to study")