File: text2html.py

package info (click to toggle)
lilypond 2.2.6-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 11,260 kB
  • ctags: 7,622
  • sloc: cpp: 47,787; lisp: 11,217; python: 11,203; sh: 3,290; yacc: 2,011; lex: 831; perl: 373; ansic: 309; makefile: 132; csh: 8
file content (40 lines) | stat: -rw-r--r-- 664 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#@PYTHON@
import os
import re
import string
import sys


entities = {
	"&" : 'amp',
	"`" : 'apos',
	'>' : 'gt',
	'<' : 'lt',
	'"' : 'quot',
	}

def txt2html (s):
	for i in entities.keys ():
		s = re.sub (i, '\001' + entities[i] + ';', s);
	s = re.sub ('\001', '&', s);
	return s

for a in sys.argv[1:]:
	# hmm, we need: text2html out/foe.txt -> out/foe.html,
	# -o is a bit overkill?
	# outfile = os.path.basename (os.path.splitext(a)[0]) + '.html'
	outfile = os.path.splitext(a)[0] + '.html'
	
	try:
	    os.unlink(outfile)
	except:
	    pass

	s = r"""
<html><body><pre>
%s
</pre></body></html>
""" % txt2html (open (a).read ())
	open (outfile, 'w').write (s)