Skip to content

Commit ed2ea3c

Browse files
authored
ci: fix html2ansi.py
1 parent d987038 commit ed2ea3c

1 file changed

Lines changed: 21 additions & 8 deletions

File tree

‎html2ansi.py‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,32 @@ def convert(input_file, output_file):
1414
"</small>": "\033[0m",
1515
}
1616

17-
for html, ansi in replacements.items():
18-
text = text.replace(html, ansi)
19-
20-
# Replace an HTML link tag with ANSI-escaped underlined blue text
2117
def convert_link(match):
2218
a_tag = match.group(1)
2319
text_inner = match.group(2)
2420
return f"\033[4;34m{text_inner}\033[0m"
2521

26-
# Replace all HTML anchor tags with ANSI-escaped text
27-
text = re.sub(r'<a\s+href="([^"]*)">([^<]*)</a>', convert_link, text)
28-
29-
return text
22+
with open(input_file, 'r', encoding='utf-8') as f_in, \
23+
open(output_file, 'w', encoding='utf-8') as f_out:
24+
25+
for line in f_in:
26+
if '\t' not in line:
27+
# Skip lines that aren't properly formatted (not tab-separated)
28+
continue
29+
30+
parts = line.strip().split('\t', 1)
31+
if len(parts) < 2:
32+
continue
33+
34+
word = parts[0]
35+
meaning = parts[1]
36+
37+
for html, ansi in replacements.items():
38+
meaning = meaning.replace(html, ansi)
39+
40+
meaning = re.sub(r'<a\s+href="([^"]*)">([^<]*)</a>', convert_link, meaning)
41+
42+
f_out.write(f"{word}\t{meaning}\n")
3043

3144
def main():
3245
if len(sys.argv) != 3:

0 commit comments

Comments
 (0)