summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Monsen <haircut@gmail.com>2024-05-23 13:47:57 -0700
committerGitHub <noreply@github.com>2024-05-23 23:47:57 +0300
commit05e9def44b36b93fac538488f75834b9f3342771 (patch)
tree4f2def69a8a0fdd9c00cc0cefc8d4258a226ad55
parent8e1bc83a86f7c04985827a0dcfcf33c1db2683e7 (diff)
add id attribute support to sidebar (#480)main
Fixes "Fragment identifier is not defined." error when trying to deep-link a sidebar. For example: ``` ERROR(RSC-012): foo.epub/EPUB/_chapter.xhtml(LINE,COLUMN): Fragment identifier is not defined. ```
-rw-r--r--lib/asciidoctor-epub3/converter.rb3
-rw-r--r--spec/xref_spec.rb16
2 files changed, 18 insertions, 1 deletions
diff --git a/lib/asciidoctor-epub3/converter.rb b/lib/asciidoctor-epub3/converter.rb
index b227afd..8786adf 100644
--- a/lib/asciidoctor-epub3/converter.rb
+++ b/lib/asciidoctor-epub3/converter.rb
@@ -735,6 +735,7 @@ document.addEventListener('DOMContentLoaded', function(event, reader) {
end
def convert_sidebar(node)
+ id_attribute = node.id ? %( id="#{node.id}") : ''
classes = ['sidebar']
if node.title?
classes << 'titled'
@@ -747,7 +748,7 @@ document.addEventListener('DOMContentLoaded', function(event, reader) {
title_attr = title_el = ''
end
- %(<aside class="#{classes * ' '}"#{title_attr} epub:type="sidebar">
+ %(<aside#{id_attribute} class="#{classes * ' '}"#{title_attr} epub:type="sidebar">
#{title_el}<div class="content">
#{output_content node}
</div>
diff --git a/spec/xref_spec.rb b/spec/xref_spec.rb
index af3471d..a5cbf0b 100644
--- a/spec/xref_spec.rb
+++ b/spec/xref_spec.rb
@@ -83,4 +83,20 @@ describe 'Asciidoctor::Epub3::Converter - Xref' do
expect(article).not_to be_nil
expect(article.content).to include '<a id="xref-_subsection" href="#_subsection" class="xref">link text</a>'
end
+
+ it 'adds xref id to sidebar' do
+ book = to_epub <<~EOS
+ = Article
+
+ [id=one]
+ ****
+ This is a sidebar
+ ****
+
+ More text
+ EOS
+ article = book.item_by_href '_article.xhtml'
+ expect(article).not_to be_nil
+ expect(article.content).to include '<aside id="one" class="sidebar" epub:type="sidebar">'
+ end
end