Skip to content

Commit

Permalink
add convert description lists to the semantic HTML 5 converter
Browse files Browse the repository at this point in the history
  • Loading branch information
redbow-kimee authored and ggrossetie committed Jul 30, 2022
1 parent d15b25e commit 2c61693
Show file tree
Hide file tree
Showing 15 changed files with 117 additions and 0 deletions.
33 changes: 33 additions & 0 deletions lib/asciidoctor/converter/semantic_html5.rb
Expand Up @@ -151,6 +151,39 @@ def convert_olist node
ret.join LF
end

def convert_dlist node
roles = []
roles << node.style if node.style
roles << node.role if node.role
role = roles.join " "
attributes = common_html_attributes node.id, role.empty? ? nil : role
if node.list_marker_keyword
attributes << %( type="#{node.list_marker_keyword}")
end
ret = []
ret << if node.title?
%(<dl#{attributes}>
<strong class="title">#{node.title}</strong>)
else
%(<dl#{attributes}>)
end
node.items.each do |terms, desc|
terms.each do |term|
ret << %(<dt>#{term.text}</dt>)
end
sub_content = if desc.blocks?
%(
#{desc.content}
)
else
""
end
ret << %(<dd>#{desc.text}#{sub_content}</dd>)
end
ret << %{</dl>}
ret.join LF
end

def convert_image node
roles = []
roles << node.role if node.role
Expand Down
@@ -0,0 +1,4 @@
[horizontal]
Description Term 1:: Description Body 1.
Description Term 2:: Description Body 2.
Description Term 3:: Description Body 3.
@@ -0,0 +1,8 @@
<dl class="horizontal">
<dt>Description Term 1</dt>
<dd>Description Body 1.</dd>
<dt>Description Term 2</dt>
<dd>Description Body 2.</dd>
<dt>Description Term 3</dt>
<dd>Description Body 3.</dd>
</dl>
@@ -0,0 +1,4 @@
[qanda#the_dl.style1.style2]
Question 1?:: Answer 1.
Question 2?:: Answer 2.
Question 3?:: Answer 3.
@@ -0,0 +1,8 @@
<dl id="the_dl" class="qanda style1 style2">
<dt>Question 1?</dt>
<dd>Answer 1.</dd>
<dt>Question 2?</dt>
<dd>Answer 2.</dd>
<dt>Question 3?</dt>
<dd>Answer 3.</dd>
</dl>
@@ -0,0 +1,4 @@
[qanda#the_dl]
Question 1?:: Answer 1.
Question 2?:: Answer 2.
Question 3?:: Answer 3.
@@ -0,0 +1,8 @@
<dl id="the_dl" class="qanda">
<dt>Question 1?</dt>
<dd>Answer 1.</dd>
<dt>Question 2?</dt>
<dd>Answer 2.</dd>
<dt>Question 3?</dt>
<dd>Answer 3.</dd>
</dl>
@@ -0,0 +1,4 @@
[qanda.style1.style2]
Question 1?:: Answer 1.
Question 2?:: Answer 2.
Question 3?:: Answer 3.
@@ -0,0 +1,8 @@
<dl class="qanda style1 style2">
<dt>Question 1?</dt>
<dd>Answer 1.</dd>
<dt>Question 2?</dt>
<dd>Answer 2.</dd>
<dt>Question 3?</dt>
<dd>Answer 3.</dd>
</dl>
@@ -0,0 +1,4 @@
[qanda]
Question 1?:: Answer 1.
Question 2?:: Answer 2.
Question 3?:: Answer 3.
@@ -0,0 +1,8 @@
<dl class="qanda">
<dt>Question 1?</dt>
<dd>Answer 1.</dd>
<dt>Question 2?</dt>
<dd>Answer 2.</dd>
<dt>Question 3?</dt>
<dd>Answer 3.</dd>
</dl>
@@ -0,0 +1,4 @@
.The Description List
Description Term 1:: Description Body 1.
Description Term 2:: Description Body 2.
Description Term 3:: Description Body 3.
@@ -0,0 +1,9 @@
<dl>
<strong class="title">The Description List</strong>
<dt>Description Term 1</dt>
<dd>Description Body 1.</dd>
<dt>Description Term 2</dt>
<dd>Description Body 2.</dd>
<dt>Description Term 3</dt>
<dd>Description Body 3.</dd>
</dl>
3 changes: 3 additions & 0 deletions test/fixtures/semantic-html5-scenarios/description-list.adoc
@@ -0,0 +1,3 @@
Description Term 1:: Description Body 1.
Description Term 2:: Description Body 2.
Description Term 3:: Description Body 3.
8 changes: 8 additions & 0 deletions test/fixtures/semantic-html5-scenarios/description-list.html
@@ -0,0 +1,8 @@
<dl>
<dt>Description Term 1</dt>
<dd>Description Body 1.</dd>
<dt>Description Term 2</dt>
<dd>Description Body 2.</dd>
<dt>Description Term 3</dt>
<dd>Description Body 3.</dd>
</dl>

0 comments on commit 2c61693

Please sign in to comment.