-
Notifications
You must be signed in to change notification settings - Fork 0
/
syntaxcolors.py
45 lines (37 loc) · 1.31 KB
/
syntaxcolors.py
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
"""
Copyright 2024 Nekoweb Wiki
This software is licensed under the 3-clause BSD license.
You should have recieved a copy of such license with this software,
if you did not, a copy can be found at the following
https://opensource.org/license/BSD-3-Clause
Otherwise, a copy of the license can be found in the root directory
of the source files, see
https://github.com/NekowebWiki/WikiGen
"""
from pygments.style import Style as PygmentsStyle
from pygments.token import Token, Comment, Keyword, Name, String, Error, Generic, Number, Operator
from pygments.formatters import HtmlFormatter
from config import COPYRIGHT_NOTICE, OUTPUT_DIR
from os.path import join as JoinPath
class WikiCode(PygmentsStyle):
background_color = "#7b8888"
styles = {
Token: "",
Comment: "#ccc",
Keyword: "#f00",
String: "italic #f99",
Number: "",
Operator: "#e9f",
Name: "#47baff",
Name.Attribute: "#b0e5ff",
}
def AddSyntaxColors():
Formatter = HtmlFormatter(
style=WikiCode,
cssclass="codehilite",
linenos="inline"
)
CSS = "\n".join(Formatter.get_style_defs().splitlines()[5:])
CopyingHeader = "/*\n" + COPYRIGHT_NOTICE + "\n*/\n"
with open(JoinPath(OUTPUT_DIR, "highlight.css"), "w") as file:
file.write(CopyingHeader+CSS)