From 6379752be9a19e57ef9358308937bcfce22cf086 Mon Sep 17 00:00:00 2001 From: vbrilon Date: Mon, 4 Jan 2016 16:03:52 -0800 Subject: [PATCH] Synta highlighting with Pygment --- .../plugins/highlight_syntax.disabled.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 cactus/skeleton/plugins/highlight_syntax.disabled.py diff --git a/cactus/skeleton/plugins/highlight_syntax.disabled.py b/cactus/skeleton/plugins/highlight_syntax.disabled.py new file mode 100644 index 00000000..b854fa5c --- /dev/null +++ b/cactus/skeleton/plugins/highlight_syntax.disabled.py @@ -0,0 +1,27 @@ +import re +import logging + +from markdown.preprocessors import Preprocessor +from markdown.extensions import Extension + +from pygments import highlight +from pygments.formatters import HtmlFormatter +from pygments.lexers import get_lexer_by_name, TextLexer + +def repl(m): + formatter = HtmlFormatter(noclasses=False, nobackground=False) + try: + lexer = get_lexer_by_name(m.group(1)) + except ValueError: + lexer = TextLexer() + code = highlight(m.group(2), lexer, formatter) + #code = code.replace('\n\n', '\n \n').replace('\n', '\n
') + return '\n\n
%s
\n\n' % code + +def preBuildPage(site, page, context, data): + pattern = re.compile(r'\[sourcecode:(.+?)\](.+?)\[/sourcecode\]', re.S) + data = re.sub(pattern, repl, data) + return context, data + + + \ No newline at end of file