Class: Pione::LiterateAction::MarkdownParser

Inherits:
Object
  • Object
show all
Defined in:
lib/pione/literate-action/markdown-parser.rb

Overview

MarkdownParser is a parser for literate action document.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(src) ⇒ MarkdownParser

Returns a new instance of MarkdownParser.



10
11
12
# File 'lib/pione/literate-action/markdown-parser.rb', line 10

def initialize(src)
  @src = src
end

Class Method Details

.parse(src) ⇒ Object

Parse the source string and return the result.



6
7
8
# File 'lib/pione/literate-action/markdown-parser.rb', line 6

def self.parse(src)
  new(src).parse
end

Instance Method Details

#parseObject

Parse the source string.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/pione/literate-action/markdown-parser.rb', line 15

def parse
  @parsed = Kramdown::Parser::GFM.parse(@src)
  current_name = nil
  root = @parsed.first
  root.children.each_with_object(Hash.new) do |elt, action|
    if name = find_rule_name(elt)
      current_name = name
      next
    end

    if current_name
      lang, content = find_action(elt)
      if content
        action[current_name] ||= {content: ""}
        action[current_name][:lang] = lang
        action[current_name][:content] << content
      end
    end
  end
end