Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Stephan Seitz
pystencils
Commits
1dcf5229
Commit
1dcf5229
authored
Mar 27, 2020
by
Stephan Seitz
Browse files
Use dark mode for code preview if user prefers `prefers-color-scheme: dark`
parent
e87b4daf
Pipeline
#22866
failed with stage
in 10 minutes and 5 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
pystencils/display_utils.py
View file @
1dcf5229
...
...
@@ -30,7 +30,13 @@ def highlight_cpp(code: str):
from
pygments.lexers
import
CppLexer
css
=
HtmlFormatter
().
get_style_defs
(
'.highlight'
)
css_tag
=
"<style>{css}</style>"
.
format
(
css
=
css
)
try
:
dark_css
=
HtmlFormatter
(
style
=
"stata-dark"
).
get_style_defs
(
'.highlight'
)
except
ModuleNotFoundError
:
dark_css
=
css
css_tag
=
"<style>{css} @media (prefers-color-scheme: dark) {{ {dark_css} }}</style>"
.
format
(
css
=
css
,
dark_css
=
dark_css
)
display
(
HTML
(
css_tag
))
return
HTML
(
highlight
(
code
,
CppLexer
(),
HtmlFormatter
()))
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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