-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadd_horizontal_scroll.py
More file actions
executable file
·56 lines (40 loc) · 1.36 KB
/
add_horizontal_scroll.py
File metadata and controls
executable file
·56 lines (40 loc) · 1.36 KB
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
import os
ROOT_DIR = "/sdcard/.workspace/web/knowlet/notes"
tag = '<div class="add-horizontal-scroll">'
count = 0
msg = ""
changed = 0
unchanged = 0
for root, _, files in os.walk(ROOT_DIR):
for file in files:
count += 1
if file.endswith(".html"):
file_path = os.path.join(root, file)
with open(file_path, "r") as r:
content = r.read()
lines = content.splitlines()
line_posn = 0
new_content = ""
msg = ""
for line in lines:
line_posn += 1
new_line = ""
if ("<table>" in line and tag + "<table>" not in line) or ("<pre>" in line and tag + "<pre>" not in line) :
new_line = line.replace("<table>", tag + "<table>").replace("<pre>", tag + "<pre>")
if ("</table>" in line and "</table></div>" not in line) or ("</pre>" in line and "</pre></div>" not in line) :
new_line = line.replace("</table>", "</table></div>").replace("</pre>", "</pre></div>")
if not new_line:
new_line = line
new_content += ("\n" if new_content else "") + new_line
if new_content != content:
with open(file_path, "w") as w:
w.write(new_content)
msg = "✔️"
changed += 1
else:
msg = "🟰"
unchanged += 1
print(msg + " " + file_path.replace(ROOT_DIR, ""))
print("total: " + str(count))
print("changed: " + str(changed))
print("unchanged: " + str(unchanged))