Method: Wikitxt::Parser::Block#body

Defined in:
lib/wikitxt/parser.rb

#bodyObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/wikitxt/parser.rb', line 14

def body
  b = BodyNode.new
  in_pre = false

  text.lines.each do |line|
    if line == "---\n"
      node = !in_pre ? PreStartNode.new : PreEndNode.new
      b.children << node
      in_pre = !in_pre
      next
    end

    if in_pre
      b.children << PreNode.new(text: line)
      next
    end

    if match = line.match(/^(?<indent> {2,})(?<text>.*)$/)
      b.children << ListNode.new(text: match[:text], indent: match[:indent].length - 2)
      next
    end

    b.children << ParagraphNode.new(text: line.chomp)
  end

  b
end