diff options
author | Markus Heiser <markus.heiser@darmarit.de> | 2023-09-06 19:12:27 +0200 |
---|---|---|
committer | Markus Heiser <markus.heiser@darmarIT.de> | 2023-09-11 12:27:56 +0200 |
commit | 935aed7ca4339a72dc9ace7297d34550e991c6f9 (patch) | |
tree | 3d93dbcb238846ac9bda79444bda8dfdb6f32594 /searxng_extra/update | |
parent | 432febd810fb45181a9b575eb71a33fcda9c7703 (diff) | |
download | searxng-935aed7ca4339a72dc9ace7297d34550e991c6f9.tar.gz searxng-935aed7ca4339a72dc9ace7297d34550e991c6f9.zip |
[feature] dark theme for code highlighter in the result list
Closes: https://github.com/searxng/searxng/issues/1354
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searxng_extra/update')
-rwxr-xr-x | searxng_extra/update/update_pygments.py | 96 |
1 files changed, 49 insertions, 47 deletions
diff --git a/searxng_extra/update/update_pygments.py b/searxng_extra/update/update_pygments.py index ca14868a2..69a8ee2db 100755 --- a/searxng_extra/update/update_pygments.py +++ b/searxng_extra/update/update_pygments.py @@ -1,69 +1,71 @@ #!/usr/bin/env python # SPDX-License-Identifier: AGPL-3.0-or-later -""" -Update pygments style +"""Update pygments style Call this script after each upgrade of pygments -""" -# pylint: disable=C0116 +""" -# set path -from os.path import join +from pathlib import Path import pygments -from pygments.formatters import HtmlFormatter # pylint: disable=E0611 -from pygments.style import Style -from pygments.token import Comment, Error, Generic, Keyword, Literal, Name, Operator, Text +from pygments.formatters import HtmlFormatter from searx import searx_dir -CSSCLASS = '.code-highlight' -RULE_CODE_LINENOS = """ .linenos { - -webkit-touch-callout: none; - -webkit-user-select: none; - -khtml-user-select: none; - -moz-user-select: none; - -ms-user-select: none; - user-select: none; - cursor: default; +LESS_FILE = Path(searx_dir) / 'static/themes/simple/src/generated/pygments.less' + +HEADER = f"""\ +/* + this file is generated automatically by searxng_extra/update/update_pygments.py + using pygments version {pygments.__version__} +*/ + +""" - &::selection { - background: transparent; /* WebKit/Blink Browsers */ - } - &::-moz-selection { - background: transparent; /* Gecko Browsers */ - } +START_LIGHT_THEME = """ +.code-highlight { +""" - margin-right: 8px; - text-align: right; -}""" +END_LIGHT_THEME = """ +} +""" +START_DARK_THEME = """ +.code-highlight-dark(){ + .code-highlight { +""" -def get_output_filename(relative_name): - return join(searx_dir, relative_name) +END_DARK_THEME = """ + } +} +""" -def get_css(cssclass, style): - result = f"""/* - this file is generated automatically by searxng_extra/update/update_pygments.py - using pygments version {pygments.__version__} -*/\n\n""" - css_text = HtmlFormatter(style=style).get_style_defs(cssclass) - result += cssclass + RULE_CODE_LINENOS + '\n\n' - for line in css_text.splitlines(): - if ' ' in line and not line.startswith(cssclass): - line = cssclass + ' ' + line - result += line + '\n' - return result +class Formatter(HtmlFormatter): + @property + def _pre_style(self): + return 'line-height: 100%;' + def get_style_lines(self, arg=None): + style_lines = [] + style_lines.extend(self.get_linenos_style_defs()) + style_lines.extend(self.get_background_style_defs(arg)) + style_lines.extend(self.get_token_style_defs(arg)) + return style_lines -def main(): - fname = 'static/themes/simple/src/generated/pygments.less' - print("update: %s" % fname) - with open(get_output_filename(fname), 'w') as f: - f.write(get_css(CSSCLASS, 'default')) +def generat_css(light_style, dark_style) -> str: + css = HEADER + START_LIGHT_THEME + for line in Formatter(style=light_style).get_style_lines(): + css += '\n ' + line + css += END_LIGHT_THEME + START_DARK_THEME + for line in Formatter(style=dark_style).get_style_lines(): + css += '\n ' + line + css += END_DARK_THEME + return css if __name__ == '__main__': - main() + print("update: %s" % LESS_FILE) + with open(LESS_FILE, 'w') as f: + f.write(generat_css('default', 'lightbulb')) |