summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan Allen <dallen@redhat.com>2013-06-13 03:04:10 -0600
committerDan Allen <dallen@redhat.com>2013-06-13 03:04:10 -0600
commitf6b186957ff8fa124334b2b62162fb97f1d9de2e (patch)
tree1981e9591d2ac29022c20e56fcee2fb3e40ed94f /lib
parent4157b907d32bd030cb56d0e63192d79c32c4d7b5 (diff)
resolves #200 add support for checklists in unordered list
Diffstat (limited to 'lib')
-rw-r--r--lib/asciidoctor/backends/html5.rb11
-rw-r--r--lib/asciidoctor/lexer.rb21
2 files changed, 28 insertions, 4 deletions
diff --git a/lib/asciidoctor/backends/html5.rb b/lib/asciidoctor/backends/html5.rb
index 3d2bca24..c8f36f4c 100644
--- a/lib/asciidoctor/backends/html5.rb
+++ b/lib/asciidoctor/backends/html5.rb
@@ -620,12 +620,17 @@ end
class BlockUlistTemplate < BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<%#encoding:UTF-8%><div#{id} class="ulist#{style_class}#{role_class}">
+<%#encoding:UTF-8%><div#{id} class="ulist<%= (checklist = (attr? 'option-checklist')) ? ' checklist' : nil %>#{style_class}#{role_class}">
#{title_div}
-<ul><%
+<ul<%= checklist ? ' type="none"' : nil %>><%
+if checklist
+ # could use &#9745 (checked ballot) and &#9744 (ballot) w/o font instead
+ marker_checked = (attr? 'icons', 'font') ? '<i class="icon-check"></i> ' : '<input type="checkbox" data-item-complete="1" checked disabled> '
+ marker_unchecked = (attr? 'icons', 'font') ? '<i class="icon-check-empty"></i> ' : '<input type="checkbox" data-item-complete="0" disabled> '
+end
content.each do |item| %>
<li>
-<p><%= item.text %></p><%
+<p><% if checklist && (item.attr? 'checkbox') %><%= (item.attr? 'checked') ? marker_checked : marker_unchecked %><% end %><%= item.text %></p><%
if item.blocks? %>
<%= item.content %><%
end %>
diff --git a/lib/asciidoctor/lexer.rb b/lib/asciidoctor/lexer.rb
index 21091f22..3201e00c 100644
--- a/lib/asciidoctor/lexer.rb
+++ b/lib/asciidoctor/lexer.rb
@@ -957,7 +957,26 @@ class Lexer
has_text = !match[3].to_s.empty?
else
# Create list item using first line as the text of the list item
- list_item = ListItem.new(list_block, match[2])
+ text = match[2]
+ checkbox = false
+ if text.start_with? '['
+ if text.start_with? '[ ] '
+ checkbox = true
+ checked = false
+ text = text[3..-1].lstrip
+ elsif text.start_with?('[*] ') || text.start_with?('[x] ')
+ checkbox = true
+ checked = true
+ text = text[3..-1].lstrip
+ end
+ end
+ list_item = ListItem.new(list_block, text)
+
+ if checkbox
+ list_block.attributes['option-checklist'] = ''
+ list_item.attributes['checkbox'] = ''
+ list_item.attributes['checked'] = '' if checked
+ end
if !sibling_trait
sibling_trait = resolve_list_marker(list_type, match[1], list_block.buffer.size, true)