Skip to content
Snippets Groups Projects
Commit 72bb4fd0 authored by Stephan Seitz's avatar Stephan Seitz
Browse files

Make highlight_style configurable

parent 1dcf5229
No related branches found
No related tags found
No related merge requests found
Pipeline #22868 passed
......@@ -176,8 +176,14 @@ def read_config():
('clear_cache_on_start', False),
])
default_highlight_style = OrderedDict([
('light_theme', 'default'),
('dark_theme', 'stata-dark'),
])
default_config = OrderedDict([('compiler', default_compiler_config),
('cache', default_cache_config)])
('cache', default_cache_config),
('highlight_style', default_highlight_style)])
config_path, config_exists = get_configuration_file_path()
config = default_config.copy()
......@@ -219,6 +225,10 @@ def get_cache_config():
return _config['cache']
def get_highlight_style_config():
return _config['highlight_style']
def add_or_change_compiler_flags(flags):
if not isinstance(flags, list) and not isinstance(flags, tuple):
flags = [flags]
......
......@@ -29,10 +29,18 @@ def highlight_cpp(code: str):
# noinspection PyUnresolvedReferences
from pygments.lexers import CppLexer
css = HtmlFormatter().get_style_defs('.highlight')
from pystencils.cpu.cpujit import get_highlight_style_config
config = get_highlight_style_config()
try:
css = HtmlFormatter(style=config['light_theme']).get_style_defs('.highlight')
except Exception:
css = HtmlFormatter(style='default').get_style_defs('.highlight')
print(f"Could not find light theme: {config['light_theme']}")
try:
dark_css = HtmlFormatter(style="stata-dark").get_style_defs('.highlight')
except ModuleNotFoundError:
dark_css = HtmlFormatter(style=config['dark_theme']).get_style_defs('.highlight')
except Exception:
dark_css = css
css_tag = "<style>{css} @media (prefers-color-scheme: dark) {{ {dark_css} }}</style>".format(css=css,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment