Class: Minidown::ListGroupElement
- Defined in:
- lib/minidown/elements/list_group_element.rb
Direct Known Subclasses
Constant Summary collapse
- IndentRegexp =
/\A\s{4,}(.+)/
- StartWithBlankRegexp =
/\A\s+(.+)/
Instance Attribute Summary collapse
-
#indent_level ⇒ Object
Returns the value of attribute indent_level.
-
#lists ⇒ Object
Returns the value of attribute lists.
Attributes inherited from Element
#children, #content, #doc, #nodes
Instance Method Summary collapse
Methods inherited from Element
#blank?, #initialize, #raw_content, #raw_content=, #to_html, #unparsed_lines
Methods included from HtmlHelper
Constructor Details
This class inherits a constructor from Minidown::Element
Instance Attribute Details
#indent_level ⇒ Object
Returns the value of attribute indent_level.
6 7 8 |
# File 'lib/minidown/elements/list_group_element.rb', line 6 def indent_level @indent_level end |
#lists ⇒ Object
Returns the value of attribute lists.
6 7 8 |
# File 'lib/minidown/elements/list_group_element.rb', line 6 def lists @lists end |
Instance Method Details
#parse ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/minidown/elements/list_group_element.rb', line 8 def parse nodes << self while line = unparsed_lines.shift #handle nested list if (line =~ UnorderListElement::NestRegexp && list_class = UnorderListElement) || (line =~ OrderListElement::NestRegexp && list_class = OrderListElement) li, str = $1.size, $2 if li > @indent_level list_class.new(doc, str, li).parse @lists.last.contents << nodes.pop next elsif li == @indent_level list_class.new(doc, str, li).parse child = nodes.pop if LineElement === nodes.last @lists.last.p_tag_content = child.lists.first.p_tag_content = true end if child.is_a?(ListGroupElement) nodes.push *child.children @lists.push *child.lists else @lists.last.contents << child end next else unparsed_lines.unshift line break end end doc.parse_line line child = nodes.pop case child when self.class if LineElement === nodes.last @lists.last.p_tag_content = child.lists.first.p_tag_content = true end nodes.push *child.children @lists.push *child.lists break when ParagraphElement contents = @lists.last.contents if line =~ StartWithBlankRegexp doc.parse_line $1 node = nodes.pop if TextElement === node || ParagraphElement === node if TextElement === contents.last contents.push(contents.pop.paragraph) end node = node.paragraph if TextElement === node end else if @blank unparsed_lines.unshift line break end node = child.text end contents << node if node when LineElement next_line = unparsed_lines.first if next_line.nil? || next_line.empty? || StartWithBlankRegexp === next_line || self.class.const_get(:ListRegexp) === next_line child.display = false nodes << child else unparsed_lines.unshift line break end else @put_back << child if child break end @blank = (LineElement === child) end children_range = (nodes.index(self) + 1)..-1 children.push *nodes[children_range] nodes[children_range] = [] nodes.push *@put_back end |