diff options
| author | Marat Radchenko <marat@slonopotamus.org> | 2024-01-07 20:43:07 +0300 |
|---|---|---|
| committer | Marat Radchenko <marat@slonopotamus.org> | 2024-01-07 20:43:07 +0300 |
| commit | 7f7ef6330584fa00e2dd3288a78d8266ce97f45d (patch) | |
| tree | 108252ef8bb7852cca5c07f92175c85226849a49 | |
| parent | 1a296d25fd27b2cb04640107bc5900909eb78c4e (diff) | |
resolves #447 fix duplicate HTML IDs in case the same footnote is used multiple times
| -rw-r--r-- | CHANGELOG.adoc | 1 | ||||
| -rw-r--r-- | lib/asciidoctor-epub3/converter.rb | 9 | ||||
| -rw-r--r-- | spec/converter_spec.rb | 4 |
3 files changed, 10 insertions, 4 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 4c013d2..5339b17 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -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 diff --git a/lib/asciidoctor-epub3/converter.rb b/lib/asciidoctor-epub3/converter.rb index d05771a..c0986db 100644 --- a/lib/asciidoctor-epub3/converter.rb +++ b/lib/asciidoctor-epub3/converter.rb @@ -460,7 +460,7 @@ document.addEventListener('DOMContentLoaded', function(event, reader) { <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> @@ -1254,9 +1254,14 @@ document.addEventListener('DOMContentLoaded', function(event, reader) { %(<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 diff --git a/spec/converter_spec.rb b/spec/converter_spec.rb index 5590042..623acd9 100644 --- a/spec/converter_spec.rb +++ b/spec/converter_spec.rb @@ -156,9 +156,9 @@ describe Asciidoctor::Epub3::Converter do 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 |
