Add sidebar block for HTML5-modified

This commit is contained in:
Gabriel Arazas 2023-11-24 11:47:28 +08:00
parent d868c0964c
commit e7e973d1c6
No known key found for this signature in database
GPG Key ID: ADE0C41DAB221FCC
2 changed files with 64 additions and 0 deletions

View File

@ -67,6 +67,22 @@ module Asciidoctor::Foodogsquared::Converters
html.to_html(indent: 2)
end
def convert_sidebar(node)
html = Nokogiri::XML::DocumentFragment.parse '<aside></aside>'
aside = html.first_element_child
add_common_attributes node, aside
if node.title?
html.document.create_element 'strong' do |strong|
strong.add_class 'title'
strong.content = node.captioned_title
aside.add_child strong
end
end
aside.inner_html += node.content
html.to_html(indent: 2)
end
# A modified version of the audio node except it can accept multiple
# sources.

View File

@ -161,4 +161,52 @@ describe Asciidoctor::Foodogsquared::Converters::HTML5Modified do
actual = (Asciidoctor.convert input).chomp
(expect actual).to eq expected.chomp
end
it 'should have a more semantic sidebar block' do
input = <<~INPUT
****
A sidebar is used for auxiliary bits of content.
****
INPUT
expected = <<~HTML
<aside><p>A sidebar is used for auxiliary bits of content.</p></aside>
HTML
actual = (Asciidoctor.convert input).chomp
(expect actual).to eq expected.chomp
end
it 'should have a more semantic sidebar block with a title' do
input = <<~INPUT
.A sidebar title
****
A sidebar is used for auxiliary bits of content.
****
INPUT
expected = <<~HTML
<aside><strong class="title">A sidebar title</strong><p>A sidebar is used for auxiliary bits of content.</p></aside>
HTML
actual = (Asciidoctor.convert input).chomp
(expect actual).to eq expected.chomp
end
it 'should have a more semantic sidebar block with a title, an ID, and several roles' do
input = <<~INPUT
[#sidebar-id.several.roles]
.A sidebar title
****
A sidebar is used for auxiliary bits of content.
****
INPUT
expected = <<~HTML
<aside id="sidebar-id" class="several roles"><strong class="title">A sidebar title</strong><p>A sidebar is used for auxiliary bits of content.</p></aside>
HTML
actual = (Asciidoctor.convert input).chomp
(expect actual).to eq expected.chomp
end
end