Commit 1dcf5229 authored by Stephan Seitz's avatar 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
......@@ -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()))
......
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