Class: Markbridge::AST::List
- Defined in:
- lib/markbridge/ast/list.rb
Overview
Represents an ordered or unordered list element.
Instance Attribute Summary
Attributes inherited from Element
Instance Method Summary collapse
-
#<<(child) ⇒ List
Add content to this list.
-
#initialize(ordered: false) ⇒ List
constructor
Create a new list element.
-
#ordered? ⇒ Boolean
Check if this is an ordered list.
Constructor Details
#initialize(ordered: false) ⇒ List
Create a new list element.
39 40 41 42 |
# File 'lib/markbridge/ast/list.rb', line 39 def initialize(ordered: false) super() @ordered = ordered end |
Instance Method Details
#<<(child) ⇒ List
Add content to this list.
-
ListItem children are added directly
-
Other nodes are wrapped in an implicit ListItem
-
Whitespace-only Text nodes are ignored
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/markbridge/ast/list.rb', line 23 def <<(child) return self if child.is_a?(Text) && child.text.strip.empty? if child.is_a?(ListItem) super else @children << ListItem.new if @children.empty? @children.last << child end self end |
#ordered? ⇒ Boolean
Check if this is an ordered list.
47 48 49 |
# File 'lib/markbridge/ast/list.rb', line 47 def ordered? @ordered end |