3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/llmed/literate_programming/markdown.rb', line 3
def parse(input)
contexts = []
current_context = { type: :context, title: "_default", content: [] }
input.each_line do |line|
if line.strip =~ /^# (.+)$/
contexts << current_context unless current_context[:content].empty?
current_context = { type: :context, title: Regexp.last_match(1), content: [] }
elsif line.strip =~ /^\[(.+)\]\((.+)\)$/
current_context[:content] << { type: :link, content: Regexp.last_match(1), reference: Regexp.last_match(2) }
elsif line.strip =~ /^#% (.+)$/
current_context[:content] << { type: :comment, content: Regexp.last_match(1) + "\n" }
elsif line.strip =~ /^#!environment\s+(\w+)\s+(.+)$/
current_context[:content] << { type: :environment, name: Regexp.last_match(1), value: Regexp.last_match(2) }
else
current_context[:content] << { type: :string, content: line }
end
end
contexts << current_context unless current_context[:content].empty?
contexts
end
|