2 # -*- coding: utf-8 -*-
13 usage = """Usage: %prog [options] SOURCE [SOURCE...]
14 Convert SOURCE files to HTML format."""
16 parser = optparse.OptionParser(usage=usage)
18 parser.add_option('-v', '--verbose', action='store_true', dest='verbose', default=False,
19 help='print status messages to stdout')
21 options, input_filenames = parser.parse_args()
23 if len(input_filenames) < 1:
28 style = etree.parse('book2html.xslt')
31 for input_filename in input_filenames:
35 output_filename = os.path.splitext(input_filename)[0] + '.html'
38 doc_file = cStringIO.StringIO()
39 expr = re.compile(r'/\s', re.MULTILINE | re.UNICODE);
41 f = open(input_filename, 'r')
43 line = line.decode('utf-8')
44 line = expr.sub(u'<br/>\n', line).replace(u'---', u'—').replace(u',,', u'„')
45 doc_file.write(line.encode('utf-8'))
50 parser = etree.XMLParser(remove_blank_text=True)
51 doc = etree.parse(doc_file, parser)
53 result = doc.xslt(style)
54 result.write(output_filename, xml_declaration=True, pretty_print=True, encoding='utf-8')