diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2019-02-24 03:58:58 -0700 |
|---|---|---|
| committer | Dan Allen <dan.j.allen@gmail.com> | 2019-02-24 03:59:47 -0700 |
| commit | ec0deb9dfa1dbdf754f7eff62c6e43d16c5d10de (patch) | |
| tree | 9738032856c44d482f6a9e74b3bc0bdea693f0ee | |
| parent | d9db048f784fb60bcceac97eaf1908ecd9ba7993 (diff) | |
only map unparsed attrlist of inline macro to target when format is short
| -rw-r--r-- | CHANGELOG.adoc | 1 | ||||
| -rw-r--r-- | lib/asciidoctor/substitutors.rb | 14 | ||||
| -rw-r--r-- | test/extensions_test.rb | 21 | ||||
| -rw-r--r-- | test/links_test.rb | 2 |
4 files changed, 29 insertions, 9 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index ec276509..2d9237bb 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -84,6 +84,7 @@ Improvements:: * populate reference text table lazily for resolving ID by reference text (#3084) * don't store fallback reference text on :bibref node (#3085) * call AbstractNode#reftext instead of AbstractNode#text to retrieve reference text for bibref node (#3085) + * only map unparsed attrlist of inline macro to target when format is short Bug Fixes:: diff --git a/lib/asciidoctor/substitutors.rb b/lib/asciidoctor/substitutors.rb index e5e2b674..83dc960c 100644 --- a/lib/asciidoctor/substitutors.rb +++ b/lib/asciidoctor/substitutors.rb @@ -559,27 +559,27 @@ module Substitutors text = text.gsub extension.instance.regexp do # honor the escape next $&.slice 1, $&.length if $&.start_with? RS - + extconf = extension.config if $~.names.empty? - target, content, extconf = $1, $2, extension.config + target, content = $1, $2 else - target, content, extconf = ($~[:target] rescue nil), ($~[:content] rescue nil), extension.config + target, content = ($~[:target] rescue nil), ($~[:content] rescue nil) end attributes = (attributes = extconf[:default_attrs]) ? attributes.dup : {} if content.nil_or_empty? attributes['text'] = content if content && extconf[:content_model] != :attributes else content = unescape_bracketed_text content + # QUESTION should we store the unparsed attrlist in the attrlist key? if extconf[:content_model] == :attributes - # QUESTION should we store the text in the _text key? - # NOTE bracked text has already been escaped parse_attributes content, extconf[:pos_attrs] || [], into: attributes else attributes['text'] = content end end - # NOTE use content if target is not set (short form only); deprecated - remove in 1.6.0 - replacement = extension.process_method[self, target || content, attributes] + # NOTE for convenience, map content (unparsed attrlist) to target when format is short + target ||= extconf[:format] == :short ? content : target + replacement = extension.process_method[self, target, attributes] Inline === replacement ? replacement.convert : replacement end end diff --git a/test/extensions_test.rb b/test/extensions_test.rb index 4825b9bc..2969386c 100644 --- a/test/extensions_test.rb +++ b/test/extensions_test.rb @@ -1128,7 +1128,26 @@ context 'Extensions' do inline_macro do named :label with_format :short - resolves_attributes false + parses_content_as :text + process do |parent, _, attrs| + %(<label>#{attrs['text']}</label>) + end + end + end + + output = convert_string_to_embedded 'label:[Checkbox]' + assert_includes output, '<label>Checkbox</label>' + ensure + Asciidoctor::Extensions.unregister_all + end + end + + test 'should map unparsed attrlist to target when format is short' do + begin + Asciidoctor::Extensions.register do + inline_macro do + named :label + with_format :short process do |parent, target| %(<label>#{target}</label>) end diff --git a/test/links_test.rb b/test/links_test.rb index bf2615df..431ad43e 100644 --- a/test/links_test.rb +++ b/test/links_test.rb @@ -860,7 +860,7 @@ context 'Links' do assert_nil ref.reftext end - test 'wip anchor with label creates reference' do + test 'anchor with label creates reference' do doc = document_from_string '[[tigers,Tigers]]Tigers roam here.' ref = doc.catalog[:refs]['tigers'] refute_nil ref |
