Class: Protos::Markdown::AST

Inherits:
Object
  • Object
show all
Defined in:
lib/protos/markdown/ast.rb

Defined Under Namespace

Classes: Node

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ AST

Returns a new instance of AST.



32
33
34
# File 'lib/protos/markdown/ast.rb', line 32

def initialize(root)
  @root = root
end

Class Method Details

.parse(content, markdown_options: {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/protos/markdown/ast.rb', line 20

def self.parse(content, markdown_options: {})
  options = {
    render: { gfm_quirks: true },
    extension: { table: true },
    **markdown_options
  }

  Commonmarker
    .parse(content, options:)
    .then { |node| new(Node.new(node)) }
end

Instance Method Details

#accept(visitor) ⇒ Object



36
37
38
39
40
# File 'lib/protos/markdown/ast.rb', line 36

def accept(visitor)
  @root.each do |node|
    Node.new(node).accept(visitor)
  end
end