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.



26
27
28
# File 'lib/protos/markdown/ast.rb', line 26

def initialize(root)
  @root = root
end

Class Method Details

.parse(content) ⇒ Object



20
21
22
23
24
# File 'lib/protos/markdown/ast.rb', line 20

def self.parse(content)
  Markly
    .parse(content, flags: Markly::GITHUB_PRE_LANG, extensions: [:table])
    .then { |node| new(Node.new(node)) }
end

Instance Method Details

#accept(visitor) ⇒ Object



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

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