Skip to content

Commit

Permalink
resolves #447 fix duplicate HTML IDs in case the same footnote is use…
Browse files Browse the repository at this point in the history
…d multiple times
  • Loading branch information
slonopotamus committed Jan 7, 2024
1 parent 1a296d2 commit 7f7ef63
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/master[
* bump the oldest supported Asciidoctor to 2.0
* escape double quotes in alt text
* refactor `btn` styling to be more customizable (#450)
* fix duplicate HTML IDs in case the same footnote is used multiple times (#447)

== 1.5.1 (2021-04-29) - @slonopotamus

Expand Down
9 changes: 7 additions & 2 deletions lib/asciidoctor-epub3/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def add_chapter(node)
<div class="footnotes">'
fns.each do |footnote|
lines << %(<aside id="note-#{footnote.index}" epub:type="footnote">
<p><sup class="noteref"><a href="#noteref-#{footnote.index}">#{footnote.index}</a></sup> #{footnote.text}</p>
<p>#{footnote.text}</p>
</aside>)
end
lines << '</div>
Expand Down Expand Up @@ -1254,9 +1254,14 @@ def convert_inline_callout(node)
%(<i class="conum" data-value="#{int_num}">#{num}</i>)
end

# @param node [Asciidoctor::Inline]
# @return [String]
def convert_inline_footnote(node)
if (index = node.attr 'index')
%(<sup class="noteref">[<a id="noteref-#{index}" href="#note-#{index}" epub:type="noteref">#{index}</a>]</sup>)
attrs = []
attrs << %(id="#{node.id}") if node.id

%(<sup class="noteref">[<a#{prepend_space attrs * ' '}href="#note-#{index}" epub:type="noteref">#{index}</a>]</sup>)
elsif node.type == :xref
%(<mark class="noteref" title="Unresolved note reference">#{node.text}</mark>)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@
expect(chapter_a).not_to be_nil
expect(chapter_b).not_to be_nil

expect(chapter_a.content).to include 'A statement.<sup class="noteref">[<a id="noteref-1" href="#note-1" epub:type="noteref">1</a>]</sup>'
expect(chapter_a.content).to include 'A statement.<sup class="noteref">[<a href="#note-1" epub:type="noteref">1</a>]</sup>'
footnote = '<aside id="note-1" epub:type="footnote">
<p><sup class="noteref"><a href="#noteref-1">1</a></sup> Clarification about this statement.</p>
<p>Clarification about this statement.</p>
</aside>'
expect(chapter_a.content).to include footnote
expect(chapter_b.content).not_to include footnote
Expand Down

0 comments on commit 7f7ef63

Please sign in to comment.