Commit b48ad915 authored by Stefan Behnel's avatar Stefan Behnel

add intro text and title to annotated HTML code file to make it more user friendly

parent 1f24710e
......@@ -3,6 +3,7 @@
from __future__ import absolute_import
import os
import os.path
import re
import codecs
import textwrap
......@@ -99,9 +100,9 @@ class AnnotationCCodeWriter(CCodeWriter):
c_file = Utils.decode_filename(os.path.basename(target_filename))
html_filename = os.path.splitext(target_filename)[0] + ".html"
with codecs.open(html_filename, "w", encoding="UTF-8") as out_buffer:
out_buffer.write(self._save_annotation(code, generated_code, c_file))
out_buffer.write(self._save_annotation(code, generated_code, c_file, source_filename))
def _save_annotation_header(self, c_file):
def _save_annotation_header(self, c_file, source_filename):
outlist = [
textwrap.dedent(u'''\
<!DOCTYPE html>
......@@ -109,6 +110,7 @@ class AnnotationCCodeWriter(CCodeWriter):
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Cython: {filename}</title>
<style type="text/css">
{css}
</style>
......@@ -117,8 +119,13 @@ class AnnotationCCodeWriter(CCodeWriter):
</script>
</head>
<body class="cython">
<p>Generated by Cython {watermark}</p>
''').format(css=self._css(), js=self._js, watermark=Version.watermark)
<p><span style="border-bottom: solid 1px grey;">Generated by Cython {watermark}</span></p>
<p>
<span style="background-color: #FFFF00">Yellow lines</span> hint at Python interaction.<br />
Click on a line that starts with a "<code>+</code>" to see the C code that Cython generated for it.
</p>
''').format(css=self._css(), js=self._js, watermark=Version.watermark,
filename=os.path.basename(source_filename) if source_filename else '')
]
if c_file:
outlist.append(u'<p>Raw output: <a href="%s">%s</a></p>\n' % (c_file, c_file))
......@@ -127,7 +134,7 @@ class AnnotationCCodeWriter(CCodeWriter):
def _save_annotation_footer(self):
return (u'</body></html>\n',)
def _save_annotation(self, code, generated_code, c_file=None):
def _save_annotation(self, code, generated_code, c_file=None, source_filename=None):
"""
lines : original cython source code split by lines
generated_code : generated c code keyed by line number in original file
......@@ -135,7 +142,7 @@ class AnnotationCCodeWriter(CCodeWriter):
c_file : filename in which the c_code has been written
"""
outlist = []
outlist.extend(self._save_annotation_header(c_file))
outlist.extend(self._save_annotation_header(c_file, source_filename))
outlist.extend(self._save_annotation_body(code, generated_code))
outlist.extend(self._save_annotation_footer())
return ''.join(outlist)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment