blob: ca14868a2793ff2f98eac57e59ebedb2de0f00ee (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#!/usr/bin/env python
# SPDX-License-Identifier: AGPL-3.0-or-later
"""
Update pygments style
Call this script after each upgrade of pygments
"""
# pylint: disable=C0116
# set path
from os.path import join
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 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;
&::selection {
background: transparent; /* WebKit/Blink Browsers */
}
&::-moz-selection {
background: transparent; /* Gecko Browsers */
}
margin-right: 8px;
text-align: right;
}"""
def get_output_filename(relative_name):
return join(searx_dir, relative_name)
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
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'))
if __name__ == '__main__':
main()
|