Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cubicweb
cubicweb
Commits
e55f6f6a8d28
Commit
ff63c0b7
authored
Oct 24, 2019
by
Laurent Peuch
Browse files
[debug/source_highlight] add highlight_html and generate_css for debugtool panels
parent
d91c229de97f
Changes
1
Hide whitespace changes
Inline
Side-by-side
cubicweb/misc/source_highlight.py
View file @
e55f6f6a
...
...
@@ -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
()
else
:
return
""
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment