diff options
-rw-r--r-- | highlighting.py | 16 | ||||
-rw-r--r-- | templates/root.mako | 7 |
2 files changed, 23 insertions, 0 deletions
diff --git a/highlighting.py b/highlighting.py new file mode 100644 index 0000000..9308b84 --- /dev/null +++ b/highlighting.py @@ -0,0 +1,16 @@ +from pygments import highlight as pygHighlight +from pygments.lexers import get_lexer_by_name +from pygments.formatters import HtmlFormatter + +formatter = HtmlFormatter(encoding = "utf-8", classprefix="pygm", nowrap=True) + +def highlight(context, code, lang): + l = get_lexer_by_name(lang, encoding = "utf-8") + context.write(pygHighlight(code, l, formatter)) + return '' + +def get_css(context): + context.write("""<style type="text/css"> +%s +</style>""" % formatter.get_style_defs()) + return '' diff --git a/templates/root.mako b/templates/root.mako index c7c7497..c20704d 100644 --- a/templates/root.mako +++ b/templates/root.mako @@ -36,12 +36,19 @@ </body> </html> +<%namespace name="_hl" module="highlighting"/> + +<%def name="hl(lang)"> + <div><pre class="box2">${_hl.highlight(capture(caller.body), lang)}</pre></div> +</%def> + <%def name="title()"> Portato </%def> <%def name="style()"> <link href=${"/static/css/style.css" | url} rel="stylesheet" type="text/css" /> + ${_hl.get_css()} </%def> <%def name="footer()"> |