Source

hack2 / codeviewer / xdemo.py

Diff from to

File codeviewer/xdemo.py

 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):
             else:
                 yield i, t
 
-code = open('/home/fijal/src/pypy/pypy/translator/goal/richards.py', 'r').read()
+FNAME = '/home/fijal/src/pypy/pypy/translator/goal/richards.py'
+code = open(FNAME, 'r').read()
 with open('pygments.css', 'w') as f:
     f.write(HtmlFormatter().get_style_defs('.highlight'))
-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)