[debug/source_highlight] add highlight_html and generate_css for debugtool panels
--- a/cubicweb/misc/source_highlight.py Thu Aug 01 05:42:45 2019 +0200
+++ b/cubicweb/misc/source_highlight.py Thu Oct 24 06:34:42 2019 +0200
@@ -6,6 +6,7 @@
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 @@
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()
+ else:
+ return ""