#!/usr/local/bin/ruby -w
@code = false
STDIN.each { |line|
# h3. xxx => ### xxx ###
re = /^(h|H)[0-9]. /
if line =~ re then
hn =line.match(re)[0].match(/[0-9]/)[0].to_i
rs = ""
hn.times { |i| rs << "#" }
line.sub!(/^(h|H)[0-9]\./, rs)
line.strip!
line = line << " #{rs}"
end
# ... "link":URL ... => ... [link](URL) ...
re = /"(\w|\s)+":(http(s)?:\/\/)(\w|\.|\/|-|:|\?|=|\+|&)+/
if line =~ re then
line.gsub!(re) { |s|
s.sub(s) {
s.sub!(/"/,'[')
s.sub!(/":/,'](')
s << ')'
s
}
}
end
if line =~ /.*<code>/ then @code = true
elsif line =~ /.*<\/code>/ then @code = false
else
line.strip!
if @code then line = " " << line end
puts line
end
}
Revised on February 19, 2008 16:08:45
by Peter Ljung
(192.16.134.68)