# charset="CP932"
# encoding="CP932"
# 表示がクソ重たい ]*>//gi;
__END__
#!/usr/bin/awk -f
# awk は範囲指定が簡単に出来る (Perl も簡単だけど ^^;;)
# この Script は Tag に改行が含まれると処理出来ない
BEGIN { IGNORECASE = 1 }
{
gsub("(table|tbody|tfoot|thead)[^>]*", "]*/, "
]*", "]*/, "]*>/, "");
}
1;# print
#!/usr/bin/env python
# python で awk 風の行 Filter.
import re
import string
import sys
retable = re.compile(r"<(/?)(?:table|tbody|tfoot|thead)\b[^>]*>", re.I)
retr = re.compile(r"<(/?)(?:tr)\b[^>]*>", re.I)
recell = re.compile(r"<(/?)(?:td|th)\b[^>]*>", re.I)
reimg = re.compile(r"]*>", re.I)
# cat したり大きい File は行毎に処理したいので Tag 中に改行を含むと処理出来ない
for x in sys.argv[1:]:
i = open(x)
o = open(x + '.new', 'w')
while 1:
L = i.readline()
if not L: break
o.write(reimg.sub('', recell.sub('<\1span>', retr.sub('<\1p>', retable.sub(r'<\1div>', L)))))
i.close()
o.close()
# 比較的小さな File なら全体を対象にすれば改行を挟んでも処理出来る
#for x in sys.argv[1:]:
# i = open(x)
# o = open(x + '.new', 'w')
# o.write(reimg.sub('', recell.sub('<\1span>', retr.sub('<\1p>', retable.sub(r'<\1div>', i.read())))))
# i.close()
# o.close()
sys.exit()