Class: Minidown::UnorderListElement

Inherits:
ListGroupElement show all
Defined in:
lib/minidown/elements/unorder_list_element.rb

Constant Summary collapse

TaskRegexp =
/\A\[([ x])\](.+)/
NestRegexp =
/\A(\s*)[*\-+]\s+(.+)/
ListRegexp =
Minidown::Utils::Regexp[:unorder_list]

Constants inherited from ListGroupElement

ListGroupElement::IndentRegexp, ListGroupElement::StartWithBlankRegexp

Instance Attribute Summary

Attributes inherited from ListGroupElement

#indent_level, #lists

Attributes inherited from Element

#children, #content, #doc, #nodes

Instance Method Summary collapse

Methods inherited from ListGroupElement

#parse

Methods inherited from Element

#blank?, #parse, #raw_content, #raw_content=, #unparsed_lines

Methods included from HtmlHelper

#br_tag, #build_tag

Constructor Details

#initialize(doc, line, indent_level = 0) ⇒ UnorderListElement

Returns a new instance of UnorderListElement.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/minidown/elements/unorder_list_element.rb', line 7

def initialize doc, line, indent_level = 0
  super doc, line
  if content =~ TaskRegexp
    @task_ul ||= true
    list = ListElement.new(doc, $2)
    list.task_list = true
    list.checked = ($1 == 'x'.freeze)
  else
    list = ListElement.new(doc, content)
  end
  @children << list
  @lists = @children.dup
  @indent_level = indent_level
  @put_back = []
end

Instance Method Details

#to_htmlObject



23
24
25
26
27
28
29
# File 'lib/minidown/elements/unorder_list_element.rb', line 23

def to_html
  attr = nil
  attr = {class: 'task-list'.freeze} if @task_ul
  build_tag 'ul'.freeze, attr do |content|
    children.each { |child| content << child.to_html}
  end
end