Commit ff63c0b7 authored by Laurent Peuch's avatar Laurent Peuch
Browse files

[debug/source_highlight] add highlight_html and generate_css for debugtool panels

parent d91c229de97f
......@@ -6,6 +6,7 @@ try:
from pygments import highlight as pygments_highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters.terminal import TerminalFormatter
from pygments.formatters.html import HtmlFormatter
has_pygments = True
except ImportError:
has_pygments = False
......@@ -19,3 +20,17 @@ def highlight(code, language):
return code
return pygments_highlight(code, get_lexer_by_name(language), TerminalFormatter())
def highlight_html(code, language, linenos=False):
if not has_pygments:
return code
return pygments_highlight(str(code), get_lexer_by_name(language), HtmlFormatter(wrapcode=True, linenos=linenos))
def generate_css():
if has_pygments:
return HtmlFormatter().get_style_defs()
return ""
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment