class Himekami::Markdown::Filters::Checkbox::List
Constants
- CHECKBOX_ATTR_CLASS
- CHECKBOX_CLOSED
- CHECKBOX_OPEN
- CHECKBOX_PATTERN
- LI_ATTR_CLASS
Public Class Methods
has_checkbox?(node)
click to toggle source
# File lib/himekami/markdown/filters/checkbox.rb, line 25 def has_checkbox?(node) node.text.start_with?(CHECKBOX_OPEN, CHECKBOX_CLOSED) end
new(node)
click to toggle source
# File lib/himekami/markdown/filters/checkbox.rb, line 30 def initialize(node) @node = node end
Public Instance Methods
convert!()
click to toggle source
# File lib/himekami/markdown/filters/checkbox.rb, line 34 def convert! add_css_class text_node add_checkbox_html end
Private Instance Methods
add_checkbox_html()
click to toggle source
# File lib/himekami/markdown/filters/checkbox.rb, line 56 def add_checkbox_html html = open_checkbox? ? render_open_checkbox_html : render_closed_checkbox_html remove_md text_node.add_previous_sibling(html) end
add_css_class()
click to toggle source
# File lib/himekami/markdown/filters/checkbox.rb, line 48 def add_css_class @node['class'] = LI_ATTR_CLASS if @node['class'].nil? || !@node['class'].include?(LI_ATTR_CLASS) end
open_checkbox?()
click to toggle source
# File lib/himekami/markdown/filters/checkbox.rb, line 71 def open_checkbox? text_node.content.start_with?(CHECKBOX_OPEN) end
remove_md()
click to toggle source
# File lib/himekami/markdown/filters/checkbox.rb, line 52 def remove_md text_node.content = text_node.content.sub(CHECKBOX_PATTERN, '').strip end
render_closed_checkbox_html()
click to toggle source
# File lib/himekami/markdown/filters/checkbox.rb, line 67 def render_closed_checkbox_html '<input type="checkbox" class="task-list-item-checkbox" checked="true" disabled="true"/>' end
render_open_checkbox_html()
click to toggle source
# File lib/himekami/markdown/filters/checkbox.rb, line 63 def render_open_checkbox_html '<input type="checkbox" class="task-list-item-checkbox" disabled="true"/>' end
text_node()
click to toggle source
# File lib/himekami/markdown/filters/checkbox.rb, line 42 def text_node return @node.children.find { |node| node.name == 'p' }.children.first if @node.children.any? { |node| node.name == 'p' } @node.children.first end