def SimpleMarkup(input_filename): inputfile = open(input_filename) markup = '<html>\n<head>\n<title>...</title>\n</head>\n<body>\n' title = True for block in blocks(inputfile): block = re.sub(r'\*(.+?)\*', r'<em>\1</em>', block) if title: markup += ('<h1>' + '\n' + block + '\n' + '<h1>' + '\n') title = False else: markup += ('<p>' + '\n' + block + '\n' + '<p>' + '\n') markup += '</body>\n</html>' html = open(input_filename + '_output.html', 'w') html.write(markup) html.close()
def feed(self, data): return data if __name__ == "__main__": import re from toblocks import blocks input_filename = r'..\test_input.txt' inputfile = open(input_filename) handler = HTMLRenderer() markup = handler.start('document') title = True for block in blocks(inputfile): block = re.sub(r'\*(.+?)\*', handler.sub('emphasis'), block) if title: markup += handler.start('title') markup += block markup += handler.end('title') title = False else: markup += handler.start('paragraph') markup += block markup += handler.end('paragraph') markup += handler.end('document') html = open(input_filename + '_handler_output.html', 'w') html.write(markup) html.close()