Class: Grokdown::Document
- Inherits:
-
Object
- Object
- Grokdown::Document
- Includes:
- Enumerable
- Defined in:
- lib/grokdown/document.rb
Instance Attribute Summary collapse
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(markdown, options: %i[DEFAULT],, extensions: %i[table tasklist strikethrough autolink])) ⇒ Document
constructor
A new instance of Document.
- #push(node) ⇒ Object
- #walk(&block) ⇒ Object
Constructor Details
#initialize(markdown, options: %i[DEFAULT],, extensions: %i[table tasklist strikethrough autolink])) ⇒ Document
Returns a new instance of Document.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/grokdown/document.rb', line 8 def initialize(markdown, options: %i[DEFAULT], extensions: %i[table tasklist strikethrough autolink]) @walk = [] @nodes = [] CommonMarker.render_doc(markdown, , extensions).walk.reduce(self) do |doc, node| decorated_node = case node when Matching Matching.for(node).build(node) else NeverComposes.new(node) end doc.push decorated_node end end |
Instance Attribute Details
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
49 50 51 |
# File 'lib/grokdown/document.rb', line 49 def nodes @nodes end |
Instance Method Details
#each(&block) ⇒ Object
52 53 54 |
# File 'lib/grokdown/document.rb', line 52 def each(&block) @nodes.each(&block) end |
#push(node) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/grokdown/document.rb', line 24 def push(node) case node when Matching _push(node) when Array node.each do |n| _push(n) end else _push(node) end self end |
#walk(&block) ⇒ Object
56 57 58 |
# File 'lib/grokdown/document.rb', line 56 def walk(&block) @walk.each(&block) end |