-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreplace_links.er
38 lines (31 loc) · 1010 Bytes
/
replace_links.er
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
glob = pyimport "glob"
re = pyimport "re"
open_file!(path) =
with! open!(path, mode:="r" , encoding:="utf_8"), f =>
data = f.read!()
data
save_file!(path, data) =
with! open!(path, mode:="w", encoding:="utf_8"), f =>
discard f.write! data
remove_links html =
PTN = "<p align='center'>\n.*\n</p>"
re.sub PTN, "", html
replace_links html =
html.replace ".md", ".html"
replace_pg_class html =
FROM = "<pre><code class=\"language-python\">"
TO = "<pre class=\"playground\"><code class=\"language-python\">"
re.sub(FROM, TO, html)
main!() =
pth = glob.glob! "tmp/*.html"
typ_pth = glob.glob! "tmp/type/*.html"
typ_adv_pth = glob.glob! "tmp/type/advanced/*.html"
paths = pth.concat(typ_pth).concat(typ_adv_pth)
for! paths, path =>
print! path
html = open_file! path
_html = remove_links html
__html = replace_pg_class _html
save_file! path, __html
if! __name__ == "__main__", do!:
main!()