1
2
3
4
5
6
7
8
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
41
42
43
44
45
46
47
|
require 'rubygems'
require 'markaby'
xhtml_tags = Markaby::XHTMLStrict.tags.map {|t| t.to_s}.join('|')
File.open(ARGV.first).readlines.each do |line|
case line
when /^(\s+)(#|if|else)(.*)/
puts [$1, '- ', $2, $3].join
when /^(\s*)(#{xhtml_tags})([. ])(.*)/
(space, tag, punc, remainder) = $1, $2, $3, $4
if remainder =~ /^(\s*)(\{)(.*)(\})\s*$/
puts [space, '%', tag, punc].join
puts [space, ' = ', $3.strip].join
else
remainder.gsub!(/\s(do|\{)\s*$/, '')
puts [space, '%', tag, punc, remainder].join
end
when /^\s*(end|\})\s*/
else
puts line
end
end
|