hgbook

annotate en/fixhtml.py @ 232:2469608b4a08

Start writing up the patchbomb extension.
author Bryan O'Sullivan <bos@serpentine.com>
date Sun May 27 09:40:12 2007 -0700 (2007-05-27)
parents
children 2e73abddad21
rev   line source
bos@149 1 #!/usr/bin/env python
bos@149 2
bos@149 3 import os
bos@149 4 import sys
bos@149 5 import re
bos@149 6
bos@149 7 unicode_re = re.compile(r'&#x00([0-7][0-9a-f]);', re.I)
bos@149 8 fancyvrb_re = re.compile(r'id="fancyvrb\d+"', re.I)
bos@149 9
bos@149 10 tmpsuffix = '.tmp.' + str(os.getpid())
bos@149 11
bos@149 12 def fix_ascii(m):
bos@149 13 return chr(int(m.group(1), 16))
bos@149 14
bos@149 15 for name in sys.argv[1:]:
bos@149 16 tmpname = name + tmpsuffix
bos@149 17 ofp = file(tmpname, 'w')
bos@149 18 for line in file(name):
bos@149 19 line = unicode_re.sub(fix_ascii, line)
bos@149 20 line = fancyvrb_re.sub('id="fancyvrb"', line)
bos@149 21 ofp.write(line)
bos@149 22 ofp.close()
bos@149 23 os.rename(tmpname, name)