From 1dcf52295394a170aef1e5e10953d80aafef5652 Mon Sep 17 00:00:00 2001 From: Stephan Seitz <stephan.seitz@fau.de> Date: Fri, 27 Mar 2020 01:16:41 +0100 Subject: [PATCH] Use dark mode for code preview if user prefers `prefers-color-scheme: dark` --- pystencils/display_utils.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pystencils/display_utils.py b/pystencils/display_utils.py index cb09197b..77e63ba2 100644 --- a/pystencils/display_utils.py +++ b/pystencils/display_utils.py @@ -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())) -- GitLab