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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/wikiscript/page_reader.rb', line 12
def self.parse( txt )
page = []
inside_table = false
table_txt = nil
txt.each_line do |line|
line = line.strip
break if line == '__END__'
next if line.start_with?( '#' ) next if line.empty?
if line =~ /^(={1,}) ## leading ======
([^=]+?) ## text (note: for now no "inline" = allowed)
=* ## (optional) trailing ====
$/x
heading_marker = $1
heading_level = $1.length heading = $2.strip
puts "heading #{heading_level} >#{heading}<"
page << [:"h#{heading_level}", heading]
elsif line.start_with?( '{|' ) inside_table = true
table_txt = String.new table_txt << line << "\n" elsif inside_table && line.start_with?( '|}' ) table_txt << line << "\n"
table = TableReader.parse_table( table_txt )
page << [:table, table]
inside_table = false
table_txt = nil
elsif inside_table
table_txt << line << "\n"
else
end
end
page
end
|