-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreplace_spans.py
More file actions
executable file
·25 lines (23 loc) · 909 Bytes
/
replace_spans.py
File metadata and controls
executable file
·25 lines (23 loc) · 909 Bytes
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
import re
import os
def replace_custom_spans(text):
"""
Converts [span_X](start_span)...[span_X](end_span)
into <span id="span_X">...</span>
"""
pattern = re.compile(r'\[span_(\d+)\]\(start_span\)(.*?)\[span_\1\]\(end_span\)', re.DOTALL)
replaced = re.sub(pattern, r'<span id="span_\1">\2</span>', text)
return replaced
root_dir = '/sdcard/.workspace/web/knowlet/notes'
# --- Run on all HTML files in current folder ---
for root, _, files in os.walk(root_dir):
for filename in files:
if re.match(r"unit_(\d+)\.html", filename):
file_path = os.path.join(root, filename)
with open(file_path, 'r', encoding='utf-8') as f:
content = f.read()
cleaned = replace_custom_spans(content)
#with open(file_path, 'w', encoding='utf-8') as f:
# f.write(cleaned)
if content != cleaned:
print(f"✔️ Updated spans in: {root.replace(root_dir, '')}")