]> git.donarmstrong.com Git - lilypond.git/blob - stepmake/bin/text2html.py
release: 1.5.24
[lilypond.git] / stepmake / bin / text2html.py
1 #@PYTHON@
2 import os
3 import re
4 import string
5 import sys
6
7
8 entities = {
9         "&" : 'amp',
10         "`" : 'apos',
11         '>' : 'gt',
12         '<' : 'lt',
13         '"' : 'quot',
14         }
15
16 def txt2html (s):
17         for i in entities.keys ():
18                 s = re.sub (i, '\001' + entities[i] + ';', s);
19         s = re.sub ('\001', '&', s);
20         return s
21
22 for a in sys.argv[1:]:
23         # hmm, we need: text2html out/foe.txt -> out/foe.html,
24         # -o is a bit overkill?
25         # outfile = os.path.basename (os.path.splitext(a)[0]) + '.html'
26         outfile = os.path.splitext(a)[0] + '.html'
27         
28         try:
29             os.unlink(outfile)
30         except:
31             pass
32
33         s = r"""
34 <html><body><pre>
35 %s
36 </pre></body></html>
37 """ % txt2html (open (a).read ())
38         open (outfile, 'w').write (s)
39
40