Source code for searxng_extra.update.update_pygments
#!/usr/bin/env python
# SPDX-License-Identifier: AGPL-3.0-or-later
"""Update pygments style
Call this script after each upgrade of pygments
"""
from pathlib import Path
import pygments
from pygments.formatters import HtmlFormatter
from searx import searx_dir
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__}
*/
"""
START_LIGHT_THEME = """
.code-highlight {
"""
END_LIGHT_THEME = """
}
"""
START_DARK_THEME = """
.code-highlight-dark(){
.code-highlight {
"""
END_DARK_THEME = """
}
}
"""
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__':
print("update: %s" % LESS_FILE)
with open(LESS_FILE, 'w') as f:
f.write(generat_css('default', 'lightbulb'))