summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2013-06-14 01:34:03 -0700
committerDan Allen <dan.j.allen@gmail.com>2013-06-14 01:34:03 -0700
commit56985f9b62b8afb76cc5131a7c8421f8d35ca0f0 (patch)
tree8b64ef69e804ba6e1298ece6f6c474351a82af49 /lib
parent3e6dc9115e522bdc44599daf022b2fd6351760b6 (diff)
parentee74119e85bb214709071be938ca5fa5abe002c3 (diff)
Merge pull request #426 from mojavelinux/checklists
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 d76a9f22..c6bca207 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 95c5a1a7..d31aa831 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 list_type == :ulist && 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)