Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add convert list methods to the semantic HTML 5 converter #4321

Open
wants to merge 6 commits into
base: feature/html-converter-next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions lib/asciidoctor/converter/semantic_html5.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,66 @@ def convert_thematic_break node
'<hr>'
end

def convert_ulist node
attributes = common_html_attributes node.id, node.role
ret = [%(<ul#{attributes}>)]
ret << %(<header><strong class="title">#{node.title}</strong><header>) if node.title?
node.items.each do |item|
ret << %(<li><span class="principal">#{item.text}</span>#{item.blocks? ? %(
#{item.content}
) : ''}</li>)
end
ret << %(</ul>)
ret.join LF
end

def convert_olist node
attributes = common_html_attributes node.id, node.role
olist_attributes = []
if node.list_marker_keyword
olist_attributes << %( type="#{node.list_marker_keyword}")
end
if node.attr? 'start'
olist_attributes << %( start="#{node.attr 'start'}")
end
if node.option? 'reversed'
olist_attributes << %( reversed="true")
end
ret = [%(<ol#{attributes}#{olist_attributes.join}>)]
ret << %(<header><strong class="title">#{node.title}</strong></header>) if node.title?
node.items.each do |item|
ret << %(<li><span class="principal">#{item.text}</span>#{item.blocks? ? %(
#{item.content}
) : ''}</li>)
end
ret << %(</ol>)
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
dlist_attributes = []
if node.list_marker_keyword
dlist_attributes << %( type="#{node.list_marker_keyword}")
end
ret = [%(<dl#{attributes}#{dlist_attributes.join}>)]
ret << %(<header><strong class="title">#{node.title}</strong></header>) if node.title?
node.items.each do |terms, desc|
terms.each do |term|
ret << %(<dt>#{term.text}</dt>)
end
ret << %(<dd><span class="principal">#{desc.text}</span>#{ desc.blocks? ? %(
#{desc.content}
) : ''}</dd>)
end
ret << %(</dl>)
ret.join LF
end

def convert_image node
roles = []
roles << node.role if node.role
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[horizontal]
Description Term 1:: Description Body 1.
Description Term 2:: Description Body 2.
Description Term 3:: Description Body 3.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<dl class="horizontal">
<dt>Description Term 1</dt>
<dd><span class="principal">Description Body 1.</span></dd>
<dt>Description Term 2</dt>
<dd><span class="principal">Description Body 2.</span></dd>
<dt>Description Term 3</dt>
<dd><span class="principal">Description Body 3.</span></dd>
</dl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[qanda#the_dl.style1.style2]
Question 1?:: Answer 1.
Question 2?:: Answer 2.
Question 3?:: Answer 3.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<dl id="the_dl" class="qanda style1 style2">
<dt>Question 1?</dt>
<dd><span class="principal">Answer 1.</span></dd>
<dt>Question 2?</dt>
<dd><span class="principal">Answer 2.</span></dd>
<dt>Question 3?</dt>
<dd><span class="principal">Answer 3.</span></dd>
</dl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[qanda#the_dl]
Question 1?:: Answer 1.
Question 2?:: Answer 2.
Question 3?:: Answer 3.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<dl id="the_dl" class="qanda">
<dt>Question 1?</dt>
<dd><span class="principal">Answer 1.</span></dd>
<dt>Question 2?</dt>
<dd><span class="principal">Answer 2.</span></dd>
<dt>Question 3?</dt>
<dd><span class="principal">Answer 3.</span></dd>
</dl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[qanda.style1.style2]
Question 1?:: Answer 1.
Question 2?:: Answer 2.
Question 3?:: Answer 3.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<dl class="qanda style1 style2">
<dt>Question 1?</dt>
<dd><span class="principal">Answer 1.</span></dd>
<dt>Question 2?</dt>
<dd><span class="principal">Answer 2.</span></dd>
<dt>Question 3?</dt>
<dd><span class="principal">Answer 3.</span></dd>
</dl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[qanda]
Question 1?:: Answer 1.
Question 2?:: Answer 2.
Question 3?:: Answer 3.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<dl class="qanda">
<dt>Question 1?</dt>
<dd><span class="principal">Answer 1.</span></dd>
<dt>Question 2?</dt>
<dd><span class="principal">Answer 2.</span></dd>
<dt>Question 3?</dt>
<dd><span class="principal">Answer 3.</span></dd>
</dl>
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<dl>
<header><strong class="title">The Description List</strong></header>
<dt>Description Term 1</dt>
<dd><span class="principal">Description Body 1.</span></dd>
<dt>Description Term 2</dt>
<dd><span class="principal">Description Body 2.</span></dd>
<dt>Description Term 3</dt>
<dd><span class="principal">Description Body 3.</span></dd>
</dl>
3 changes: 3 additions & 0 deletions test/fixtures/semantic-html5-scenarios/description-list.adoc
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<dl>
<dt>Description Term 1</dt>
<dd><span class="principal">Description Body 1.</span></dd>
<dt>Description Term 2</dt>
<dd><span class="principal">Description Body 2.</span></dd>
<dt>Description Term 3</dt>
<dd><span class="principal">Description Body 3.</span></dd>
</dl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.The List
. alice
.. subpoint 1
.. subpoint 2
. bob
.. subpoint 1
.. subpoint 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<ol>
<header><strong class="title">The List</strong></header>
<li><span class="principal">alice</span>
<ol type="a">
<li><span class="principal">subpoint 1</span></li>
<li><span class="principal">subpoint 2</span></li>
</ol>
</li>
<li><span class="principal">bob</span>
<ol type="a">
<li><span class="principal">subpoint 1</span></li>
<li><span class="principal">subpoint 2</span></li>
</ol>
</li>
</ol>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
. alice
.. subpoint 1
.. subpoint 2
. bob
.. subpoint 1
.. subpoint 2
14 changes: 14 additions & 0 deletions test/fixtures/semantic-html5-scenarios/nested-ordered-list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<ol>
<li><span class="principal">alice</span>
<ol type="a">
<li><span class="principal">subpoint 1</span></li>
<li><span class="principal">subpoint 2</span></li>
</ol>
</li>
<li><span class="principal">bob</span>
<ol type="a">
<li><span class="principal">subpoint 1</span></li>
<li><span class="principal">subpoint 2</span></li>
</ol>
</li>
</ol>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.List Title
* alice
** subpoint 1
** subpoint 2
* bob
** subpoint 1
** subpoint 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<ul>
<header><strong class="title">List Title</strong><header>
<li><span class="principal">alice</span>
<ul>
<li><span class="principal">subpoint 1</span></li>
<li><span class="principal">subpoint 2</span></li>
</ul>
</li>
<li><span class="principal">bob</span>
<ul>
<li><span class="principal">subpoint 1</span></li>
<li><span class="principal">subpoint 2</span></li>
</ul>
</li>
</ul>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
* alice
** subpoint 1
** subpoint 2
* bob
** subpoint 1
** subpoint 2
14 changes: 14 additions & 0 deletions test/fixtures/semantic-html5-scenarios/nested-unordered-list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<ul>
<li><span class="principal">alice</span>
<ul>
<li><span class="principal">subpoint 1</span></li>
<li><span class="principal">subpoint 2</span></li>
</ul>
</li>
<li><span class="principal">bob</span>
<ul>
<li><span class="principal">subpoint 1</span></li>
<li><span class="principal">subpoint 2</span></li>
</ul>
</li>
</ul>
11 changes: 11 additions & 0 deletions test/fixtures/semantic-html5-scenarios/ordered-list-roman.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
["upperroman"]
1. step 1
2. step 2
3. step 3

//

["lowerroman"]
. step 1
. step 2
. step 3
10 changes: 10 additions & 0 deletions test/fixtures/semantic-html5-scenarios/ordered-list-roman.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<ol type="I">
<li><span class="principal">step 1</span></li>
<li><span class="principal">step 2</span></li>
<li><span class="principal">step 3</span></li>
</ol>
<ol type="i">
<li><span class="principal">step 1</span></li>
<li><span class="principal">step 2</span></li>
<li><span class="principal">step 3</span></li>
</ol>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[#list_a.class_a.class_b]
1. step 1
2. step 2
3. step 3

//

[#list_b.class_c.class_d]
. step 1
. step 2
. step 3
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<ol id="list_a" class="class_a class_b">
<li><span class="principal">step 1</span></li>
<li><span class="principal">step 2</span></li>
<li><span class="principal">step 3</span></li>
</ol>
<ol id="list_b" class="class_c class_d">
<li><span class="principal">step 1</span></li>
<li><span class="principal">step 2</span></li>
<li><span class="principal">step 3</span></li>
</ol>
11 changes: 11 additions & 0 deletions test/fixtures/semantic-html5-scenarios/ordered-list-with-id.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[#list_a]
1. step 1
2. step 2
3. step 3

//

[#list_b]
. step 1
. step 2
. step 3
10 changes: 10 additions & 0 deletions test/fixtures/semantic-html5-scenarios/ordered-list-with-id.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<ol id="list_a">
<li><span class="principal">step 1</span></li>
<li><span class="principal">step 2</span></li>
<li><span class="principal">step 3</span></li>
</ol>
<ol id="list_b">
<li><span class="principal">step 1</span></li>
<li><span class="principal">step 2</span></li>
<li><span class="principal">step 3</span></li>
</ol>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[%reversed]
. step 3
. step 2
. step 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ol reversed="true">
<li><span class="principal">step 3</span></li>
<li><span class="principal">step 2</span></li>
<li><span class="principal">step 1</span></li>
</ol>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[start=3]
. step 3
. step 4
. step 5
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ol start="3">
<li><span class="principal">step 3</span></li>
<li><span class="principal">step 4</span></li>
<li><span class="principal">step 5</span></li>
</ol>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.List A
1. step 1
2. step 2
3. step 3

//

.List B
. step 1
. step 2
. step 3
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<ol>
<header><strong class="title">List A</strong></header>
<li><span class="principal">step 1</span></li>
<li><span class="principal">step 2</span></li>
<li><span class="principal">step 3</span></li>
</ol>
<ol>
<header><strong class="title">List B</strong></header>
<li><span class="principal">step 1</span></li>
<li><span class="principal">step 2</span></li>
<li><span class="principal">step 3</span></li>
</ol>
9 changes: 9 additions & 0 deletions test/fixtures/semantic-html5-scenarios/ordered-list.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
1. step 1
2. step 2
3. step 3

//

. step 1
. step 2
. step 3
Loading
Loading