Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert figure element's xml:id attribute into ID anchor to enable linking to figures #59

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/docbookrx/docbook_visitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1485,6 +1485,9 @@ def visit_screenshot node
# FIXME share logic w/ visit_inlinemediaobject, which is the same here except no block_title and uses append_text, not append_line
def visit_figure node
append_blank_line
if (id = (resolve_id node, normalize: @normalize_ids))
append_line %([[#{id}]])
end
append_block_title node
if (image_node = node.at_css('imageobject imagedata'))
src = image_node.attr('fileref')
Expand Down
34 changes: 33 additions & 1 deletion spec/lib/docbookrx/docbookrx_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,39 @@
EOS
output = Docbookrx.convert input
expect(output).to eq(expected)
end
end

it 'adds an XML ID for figures' do

input = <<-EOS
<article xmlns='http://docbook.org/ns/docbook'
xmlns:xl="http://www.w3.org/1999/xlink"
version="5.0" xml:lang="en">
<para>See <xref linkend="sample-figure"/>
<figure xml:id="sample-figure">
<title>Local History</title>
<mediaobject>
<imageobject>
<imagedata fileref="images/dummy.png"/>
</imageobject>
</mediaobject>
</figure>

</article>
EOS

expected = <<-EOS.rstrip
See <<_sample_figure>>

[[_sample_figure]]
.Local History
image::images/dummy.png[]
EOS

output = Docbookrx.convert input

expect(output).to include(expected)
end

it 'should correctly convert varlistentry elements with nested lists' do
input = <<-EOS
Expand Down