9
10
11
12
13
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/markdown_formatter/ast.rb', line 9
def traverse(parent = [@ast])
parent.each do |node|
case node[:type]
when :root
traverse(node[:children])
when :blank
when :p
str = ASTNode::Paragraph.new(node).to_s
unless @source.sub!(node.dig(:options, :raw_text).chomp) { |m| str.gsub(/\R(?!\z)/, " ").chomp }
raise "Parse Failed!!"
end
when :ul, :ol, :blockquote
str = ASTNode::ContainerBlock.new(node).to_s
unless @source.sub!(node.dig(:options, :raw_text), str)
raise "Parse Failed!!"
end
when :header
when :hr
when :codeblock
when :table
else
pp node
raise "Unexpected type #{node[:type]}"
end
end
end
|