Skip to content

Commit

Permalink
catalog inline ref defined using anchor macro even when resolved reft…
Browse files Browse the repository at this point in the history
…ext is empty
  • Loading branch information
mojavelinux committed Apr 26, 2023
1 parent ee15103 commit 8baf1e3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Improvements::

Bug Fixes::

* Catalog inline ref defined using anchor macro even when resolved reftext is empty
* Use while loop rather than recursion to locate next line to process; prevents stack limit error (#4368)
* Avoid numeric character reference when looking for fragment in target of xref (#4393, #3642)
* Use correct selector to collapse margin on first and last child of sidebar
Expand Down
2 changes: 1 addition & 1 deletion lib/asciidoctor/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,7 @@ def self.catalog_inline_anchors text, block, document, reader
reftext = reftext.gsub '\]', ']'
reftext = document.sub_attributes reftext if reftext.include? ATTR_REF_HEAD
elsif reftext.include? ATTR_REF_HEAD
next if (reftext = document.sub_attributes reftext).empty?
reftext = nil if (reftext = document.sub_attributes reftext).empty?
end
end
end
Expand Down
10 changes: 10 additions & 0 deletions test/links_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,16 @@
assert_includes output, (input.sub '{empty}', '')
end

test 'reftext of macro inline ref can resolve to empty' do
input = 'anchor:id-only[{empty}]text\n\nsee <<id-only>>'
doc = document_from_string input
assert doc.catalog[:refs].key? 'id-only'
output = doc.convert standalone: false
assert_xpath '//a[@id="id-only"]', output, 1
assert_xpath '//a[@href="#id-only"]', output, 1
assert_xpath '//a[@href="#id-only"][text()="[id-only]"]', output, 1
end

test 'inline ref with reftext' do
%w([[tigers,Tigers]] anchor:tigers[Tigers]).each do |anchor|
doc = document_from_string %(Here you can read about tigers.#{anchor})
Expand Down

0 comments on commit 8baf1e3

Please sign in to comment.