-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbump_katex.py
41 lines (37 loc) · 1.43 KB
/
bump_katex.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
import lxml.html as lh
from pathlib import Path
for f in Path("api-docs/docs-2.4/sphinx/html").glob("**/*.html"):
print(f)
doc = lh.parse(str(f))
head = doc.find("head")
for l in head.findall("link"):
if "jsdelivr" not in l.get("href", ""):
continue
l.set("href", "https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css")
l.set(
"integrity",
"sha384-zB1R0rpPzHqg7Kpt0Aljp8JPLqbXI3bhnPWROx27a9N0Ll6ZP/+DiW/UqRcLbRjq",
)
l.set("crossorigin", "anonymous")
for l in head.findall("script"):
if "jsdelivr" not in l.get("src", ""):
continue
if "katex.min.js" in l.get("src"):
l.set("src", "https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js")
l.set(
"integrity",
"sha384-y23I5Q6l+B6vatafAwxRu/0oK/79VlbSz7Q9aiSZUvyWYIYsd+qj+o24G5ZU2zJz",
)
elif "auto-render.min.js" in l.get("src"):
l.set(
"src",
"https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js",
)
l.set(
"integrity",
"sha384-kWPLUVMOks5AQFrykwIup5lo0m3iMkkHrD0uJ4H5cjeGihAutqP0yW0J6dpFiVkI",
)
l.set("defer", None)
l.set("crossorigin", "anonymous")
with open(f, "w") as file_obj:
file_obj.write(lh.tostring(doc).decode("utf-8"))