mirror of
https://github.com/foo-dogsquared/asciidoctor-foodogsquared-extensions.git
synced 2025-01-30 22:57:56 +00:00
Add admonition block for HTML5-modified
This commit is contained in:
parent
74c48a345f
commit
153e110489
@ -30,6 +30,42 @@ module Asciidoctor::Foodogsquared::Converters
|
||||
html.to_html
|
||||
end
|
||||
|
||||
def convert_admonition(node)
|
||||
html = Nokogiri::XML::DocumentFragment.parse '<aside></aside>'
|
||||
|
||||
aside = html.first_element_child
|
||||
aside['data-admonition-type'] = node.attr 'name'
|
||||
|
||||
add_common_attributes node, aside
|
||||
|
||||
if node.document.attr? 'icons', 'image'
|
||||
html.document.create_element 'svg' do |svg|
|
||||
html.document.create_element 'use' do |use|
|
||||
use['href'] = "#{node.image_uri "#{node.attr 'name'}.svg", 'iconsdir'}##{node.attr 'name'}"
|
||||
use['alt'] = node.attr 'textlabel'
|
||||
svg.add_child use
|
||||
end
|
||||
aside.add_child svg
|
||||
end
|
||||
else
|
||||
html.document.create_element 'div' do |div|
|
||||
div.add_class 'admonition-label'
|
||||
div.content = node.attr 'textlabel'
|
||||
aside.add_child div
|
||||
end
|
||||
end
|
||||
|
||||
if node.title?
|
||||
html.document.create_element 'strong', class: 'title' 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
|
||||
|
||||
def add_common_attributes(node, html)
|
||||
html['id'] = node.id if node.id
|
||||
|
@ -29,4 +29,40 @@ describe Asciidoctor::Foodogsquared::Converters::HTML5Modified do
|
||||
actual = (Asciidoctor.convert input).chomp
|
||||
(expect actual).to eq expected.chomp
|
||||
end
|
||||
|
||||
it 'should have a more semantic version of the admonitions' do
|
||||
input = <<~INPUT
|
||||
[WARNING]
|
||||
====
|
||||
Hello there
|
||||
====
|
||||
INPUT
|
||||
|
||||
expected = <<~HTML
|
||||
<aside data-admonition-type="warning"><div class="admonition-label">Warning</div>
|
||||
<p>Hello there</p></aside>
|
||||
HTML
|
||||
|
||||
actual = (Asciidoctor.convert input).chomp
|
||||
(expect actual).to eq expected.chomp
|
||||
end
|
||||
|
||||
it 'should have a more semantic version of the admonitions even with typical Asciidoc elements' do
|
||||
input = <<~INPUT
|
||||
[#warning-id.big.reversed]
|
||||
.A warning
|
||||
[WARNING]
|
||||
====
|
||||
Hello there
|
||||
====
|
||||
INPUT
|
||||
|
||||
expected = <<~HTML
|
||||
<aside data-admonition-type="warning" id="warning-id" class="big reversed"><div class="admonition-label">Warning</div>
|
||||
<strong class="title">A warning</strong><p>Hello there</p></aside>
|
||||
HTML
|
||||
|
||||
actual = (Asciidoctor.convert input).chomp
|
||||
(expect actual).to eq expected.chomp
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user