hack2 / codeviewer /

Diff from to

File codeviewer/

 from pygments.lexers import PythonLexer
 from pygments.formatters import HtmlFormatter
 from jinja2 import Template
+import json
 class CustomHtmlFormatter(HtmlFormatter):
+    def __init__(self, codelines):
+        self.codelines = codelines
+        HtmlFormatter.__init__(self)
     def wrap(self, source, outfile):
         total = 1
         for i, t in HtmlFormatter.wrap(self, source, outfile):
                 yield i, t
-code = open('/home/fijal/src/pypy/pypy/translator/goal/', 'r').read()
+FNAME = '/home/fijal/src/pypy/pypy/translator/goal/'
+code = open(FNAME, 'r').read()
 with open('pygments.css', 'w') as f:
-with open('x.html', 'w') as f:
-    source = highlight(code, PythonLexer(), CustomHtmlFormatter())
-    f.write(Template(open("file.jinja").read()).render(source=source))
+with open('main.html', 'w') as f:
+    f.write(Template(open("file.jinja").read()).render())
+with open("x.html", "w") as f:
+    source = highlight(code, PythonLexer(), CustomHtmlFormatter(code.splitlines()))
+    f.write(source)
+with open("x.json", "w") as f:
+    json.dump(code.splitlines(), f)