summaryrefslogtreecommitdiff
path: root/highlighting.py
blob: 9308b848165514e53cc0f21d2499ae37d22c1aef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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 ''