diff options
Diffstat (limited to '')
-rw-r--r-- | highlighting.py | 12 | ||||
-rwxr-xr-x | index.py | 4 | ||||
-rw-r--r-- | renderer.py | 3 | ||||
-rw-r--r-- | templates/root.mako | 2 |
4 files changed, 9 insertions, 12 deletions
diff --git a/highlighting.py b/highlighting.py index f859920..439ae78 100644 --- a/highlighting.py +++ b/highlighting.py @@ -7,13 +7,11 @@ formatter = HtmlFormatter(encoding = "utf-8", classprefix="pygm", nowrap=True) BashLexer.tokens["basic"].append((r'\b(emerge|layman|git(?!:))\s*\b(?!\.)', Name.Builtin)) -def highlight(context, code, lang): +def highlight(code, lang): l = get_lexer_by_name(lang, encoding = "utf-8") - context.write(pygHighlight(code, l, formatter)) - return '' + return pygHighlight(code, l, formatter) -def get_css(context): - context.write("""<style type="text/css"> +def get_css(): + return """<style type="text/css"> %s -</style>""" % formatter.get_style_defs()) - return '' +</style>""" % formatter.get_style_defs() @@ -7,8 +7,8 @@ import controller # URL Mappings # urls = ( - "/r/(.*)", "controller.Redirect", - "/(.*)", "controller.Page" + "/r/(.*)", controller.Redirect, + "/(.*)", controller.Page ) # diff --git a/renderer.py b/renderer.py index 5e19a92..ba08e36 100644 --- a/renderer.py +++ b/renderer.py @@ -4,6 +4,7 @@ import mako from mako.lookup import TemplateLookup import helper +import highlighting class Renderer: """ @@ -23,7 +24,7 @@ class Renderer: except mako.exceptions.TopLevelLookupException, e: raise web.ctx.app_stack[-1].notfound(tpl) - return t.render(h = helper, url = helper.url, w = web, **kwargs) + return t.render(h = helper, url = helper.url, w = web, _hl = highlighting, **kwargs) __call__ = render diff --git a/templates/root.mako b/templates/root.mako index 72dac01..39ee098 100644 --- a/templates/root.mako +++ b/templates/root.mako @@ -38,8 +38,6 @@ ## functions -<%namespace name="_hl" module="highlighting"/> - <%def name="hl(lang)"> <pre class="box">${_hl.highlight(capture(caller.body), lang)}</pre> </%def> |