# table.rb
# http://www14.cds.ne.jp/~not/tawagoto/200102b.html#11_t1
=begin
使い方は、1行目に「Table:」と書いといて、それぞれの値をタブ区切りで記述します。
"[", "]" で囲った要素は
にします。あと数字っぽいものは勝手に右寄せ。
Table:
[hoge1] [hoge2] [hoge3]
[foo] test1 test2 test3
[bar] -10 20% \10,000
=end
class Filter
def table(str, type)
case type
when :PRE
if str.sub!(/\A(table:\s*\n)/i, '') then
table = "\n"
str.each{ |line|
table << "\t"
line.chomp.split(/\t/).each{ |item|
if /^\[(.+)\]/ =~ item then
table << "| #$1 | "
elsif /^[+-\\]?[\d,\.]+%?/ =~ item
table << "#{item} | "
else
table << "#{item} | "
end
}
table << " \n"
}
table << " \n\n"
str.replace(table)
return :THROUGH
end
end
end
end
|