from pygments import highlight as pygHighlight from pygments.token import Name from pygments.lexers import get_lexer_by_name, BashLexer from pygments.formatters import HtmlFormatter 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): l = get_lexer_by_name(lang, encoding = "utf-8") context.write(pygHighlight(code, l, formatter)) return '' def get_css(context): context.write("""""" % formatter.get_style_defs()) return ''