2020-09-16 06:53:05 +00:00
|
|
|
#!/usr/bin/env python
|
2024-03-10 14:33:23 +00:00
|
|
|
# lint: pylint
|
2021-10-03 13:12:09 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
2023-09-06 17:12:27 +00:00
|
|
|
"""Update pygments style
|
2020-09-16 06:53:05 +00:00
|
|
|
|
|
|
|
Call this script after each upgrade of pygments
|
|
|
|
|
2023-09-06 17:12:27 +00:00
|
|
|
"""
|
2024-03-10 14:33:23 +00:00
|
|
|
# pylint: disable=too-few-public-methods
|
2020-09-16 06:53:05 +00:00
|
|
|
|
2023-09-06 17:12:27 +00:00
|
|
|
from pathlib import Path
|
2020-09-16 06:53:05 +00:00
|
|
|
import pygments
|
2024-03-10 14:33:23 +00:00
|
|
|
from pygments.formatters.html import HtmlFormatter
|
2020-09-16 06:53:05 +00:00
|
|
|
|
|
|
|
from searx import searx_dir
|
|
|
|
|
2023-09-06 17:12:27 +00:00
|
|
|
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__}
|
|
|
|
*/
|
|
|
|
|
|
|
|
"""
|
2021-04-26 17:06:30 +00:00
|
|
|
|
2023-09-06 17:12:27 +00:00
|
|
|
START_LIGHT_THEME = """
|
|
|
|
.code-highlight {
|
|
|
|
"""
|
2020-09-16 06:53:05 +00:00
|
|
|
|
2023-09-06 17:12:27 +00:00
|
|
|
END_LIGHT_THEME = """
|
|
|
|
}
|
|
|
|
"""
|
2020-09-16 06:53:05 +00:00
|
|
|
|
2023-09-06 17:12:27 +00:00
|
|
|
START_DARK_THEME = """
|
|
|
|
.code-highlight-dark(){
|
|
|
|
.code-highlight {
|
|
|
|
"""
|
2020-09-16 06:53:05 +00:00
|
|
|
|
2023-09-06 17:12:27 +00:00
|
|
|
END_DARK_THEME = """
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
2020-09-16 06:53:05 +00:00
|
|
|
|
|
|
|
|
2024-03-10 14:33:23 +00:00
|
|
|
class Formatter(HtmlFormatter): # pylint: disable=missing-class-docstring
|
2023-09-06 17:12:27 +00:00
|
|
|
@property
|
|
|
|
def _pre_style(self):
|
|
|
|
return 'line-height: 100%;'
|
2020-09-16 06:53:05 +00:00
|
|
|
|
2023-09-06 17:12:27 +00:00
|
|
|
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
|
2020-09-16 06:53:05 +00:00
|
|
|
|
2021-04-26 17:06:30 +00:00
|
|
|
|
2023-09-06 17:12:27 +00:00
|
|
|
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
|
2020-09-16 06:53:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2023-09-06 17:12:27 +00:00
|
|
|
print("update: %s" % LESS_FILE)
|
2024-03-10 14:33:23 +00:00
|
|
|
with LESS_FILE.open('w', encoding='utf8') as f:
|
2023-09-06 17:12:27 +00:00
|
|
|
f.write(generat_css('default', 'lightbulb'))
|