Skip to content

Commit

Permalink
add id attribute support to sidebar (#480)
Browse files Browse the repository at this point in the history
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.
```
  • Loading branch information
meonkeys committed May 23, 2024
1 parent 8e1bc83 commit 05e9def
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/asciidoctor-epub3/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ def convert_verse(node)
end

def convert_sidebar(node)
id_attribute = node.id ? %( id="#{node.id}") : ''
classes = ['sidebar']
if node.title?
classes << 'titled'
Expand All @@ -747,7 +748,7 @@ def convert_sidebar(node)
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>
Expand Down
16 changes: 16 additions & 0 deletions spec/xref_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,20 @@
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

0 comments on commit 05e9def

Please sign in to comment.