-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhtml-generation.py
33 lines (24 loc) · 978 Bytes
/
html-generation.py
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
import parser
import sys
import tornado
import tornado.template
import pygments
import pygments.lexers
import pygments.formatters
if __name__ == "__main__":
filename = sys.argv[1]
p = parser.Parser(open(filename))
functions = p.parse_functions()
loader = tornado.template.Loader('./', autoescape=None)
template = loader.load('base.html')
lexer = pygments.lexers.PythonLexer()
formatter = pygments.formatters.HtmlFormatter(cssclass='highlight', style='monokai', linenos='inline')
cssfilename = './style.css'
cssfile = open(cssfilename, 'w')
cssfile.write(formatter.get_style_defs('.highlight'))
cssfile.close()
def highlight(code):
formatter.linenostart = code.min_line + 1
return pygments.highlight(code.body, lexer, formatter)
styled_functions = map(highlight, functions)
print template.generate(functions=functions, styled_functions=styled_functions, filename=filename, cssfilename=cssfilename)