Commit 59d09fd4 authored by Stefan Behnel's avatar Stefan Behnel

tweak templating in annotated code writer some more

parent f2336b61
......@@ -3,6 +3,7 @@
import os
import re
import codecs
import textwrap
from xml.sax.saxutils import escape as html_escape
from StringIO import StringIO
......@@ -62,28 +63,28 @@ class AnnotationCCodeWriter(CCodeWriter):
if (theDiv.style.display != 'block') theDiv.style.display = 'block';
else theDiv.style.display = 'none';
}
"""
""".strip()
_css_template = """
body.cython { font-family: courier; font-size: 12; }
_css_template = textwrap.dedent("""
body.cython { font-family: courier; font-size: 12; }
.cython.tag { }
.cython.line { margin: 0em }
.cython.code { font-size: 9; color: #444444; display: none; margin-left: 20px; }
.cython.tag { }
.cython.line { margin: 0em }
.cython.code { font-size: 9; color: #444444; display: none; margin-left: 20px; }
.cython.code .py_c_api { color: red; }
.cython.code .py_macro_api { color: #FF7000; }
.cython.code .pyx_c_api { color: #FF3000; }
.cython.code .pyx_macro_api { color: #FF7000; }
.cython.code .refnanny { color: #FFA000; }
.cython.code .error_goto { color: #FFA000; }
.cython.code .py_c_api { color: red; }
.cython.code .py_macro_api { color: #FF7000; }
.cython.code .pyx_c_api { color: #FF3000; }
.cython.code .pyx_macro_api { color: #FF7000; }
.cython.code .refnanny { color: #FFA000; }
.cython.code .error_goto { color: #FFA000; }
.cython.code .coerce { color: #008000; border: 1px dotted #008000 }
.cython.code .py_attr { color: #FF0000; font-weight: bold; }
.cython.code .c_attr { color: #0000FF; }
.cython.code .py_call { color: #FF0000; font-weight: bold; }
.cython.code .c_call { color: #0000FF; }
"""
.cython.code .coerce { color: #008000; border: 1px dotted #008000 }
.cython.code .py_attr { color: #FF0000; font-weight: bold; }
.cython.code .c_attr { color: #0000FF; }
.cython.code .py_call { color: #FF0000; font-weight: bold; }
.cython.code .c_call { color: #0000FF; }
""")
def save_annotation(self, source_filename, target_filename):
with Utils.open_source_file(source_filename) as f:
......@@ -92,14 +93,15 @@ body.cython { font-family: courier; font-size: 12; }
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(lines, code_source_file , c_file))
out_buffer.write(self._save_annotation(lines, code_source_file, c_file))
def _save_annotation_header(self, c_file):
outlist = [u'''
<!DOCTYPE html>
<!-- Generated by Cython {watermark} -->
<html>
<head>
outlist = [
textwrap.dedent(u'''\
<!DOCTYPE html>
<!-- Generated by Cython {watermark} -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
{css}
......@@ -107,10 +109,11 @@ body.cython { font-family: courier; font-size: 12; }
<script>
{js}
</script>
</head>
<body class="cython">
<p>Generated by Cython {watermark}</p>\n'''.format(
css=self._css(), js=self._js, watermark=Version.watermark)]
</head>
<body class="cython">
<p>Generated by Cython {watermark}</p>
''').format(css=self._css(), js=self._js, watermark=Version.watermark)
]
if c_file:
outlist.append(u'<p>Raw output: <a href="%s">%s</a></p>\n' % (c_file, c_file))
return outlist
......@@ -127,11 +130,11 @@ body.cython { font-family: courier; font-size: 12; }
"""
outlist = []
outlist.extend(self._save_annotation_header(c_file))
outlist.extend(self._save_annotation_body(lines, code_source_file, c_file=None))
outlist.extend(self._save_annotation_body(lines, code_source_file))
outlist.extend(self._save_annotation_footer())
return ''.join(outlist)
def _save_annotation_body(self, lines, code_source_file, c_file=None):
def _save_annotation_body(self, lines, code_source_file):
outlist = []
pos_comment_marker = u'/* \N{HORIZONTAL ELLIPSIS} */\n'
new_calls_map = dict(
......
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