Skip to content
Snippets Groups Projects
Commit e64f3357 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
No related branches found
No related tags found
No related merge requests found
...@@ -30,7 +30,10 @@ def highlight_cpp(code: str): ...@@ -30,7 +30,10 @@ def highlight_cpp(code: str):
from pygments.lexers import CppLexer from pygments.lexers import CppLexer
css = HtmlFormatter().get_style_defs('.highlight') css = HtmlFormatter().get_style_defs('.highlight')
css_tag = "<style>{css}</style>".format(css=css) dark_css = HtmlFormatter(style="stata-dark").get_style_defs('.highlight')
css_tag = "<style>{css} @media (prefers-color-scheme: dark) {{ {dark_css} }}</style>".format(css=css,
dark_css=dark_css)
display(HTML(css_tag)) display(HTML(css_tag))
return HTML(highlight(code, CppLexer(), HtmlFormatter())) return HTML(highlight(code, CppLexer(), HtmlFormatter()))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment