Mercurial > yakumo_izuru > aya
comparison vendor/github.com/alecthomas/chroma/v2/table.py @ 66:787b5ee0289d draft
Use vendored modules
Signed-off-by: Izuru Yakumo <yakumo.izuru@chaotic.ninja>
author | yakumo.izuru |
---|---|
date | Sun, 23 Jul 2023 13:18:53 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
65:6d985efa0f7a | 66:787b5ee0289d |
---|---|
1 #!/usr/bin/env python3 | |
2 import re | |
3 from collections import defaultdict | |
4 from subprocess import check_output | |
5 | |
6 README_FILE = "README.md" | |
7 | |
8 | |
9 lines = check_output(["go", "run", "./cmd/chroma/main.go", "--list"]).decode("utf-8").splitlines() | |
10 lines = [line.strip() for line in lines if line.startswith(" ") and not line.startswith(" ")] | |
11 lines = sorted(lines, key=lambda l: l.lower()) | |
12 | |
13 table = defaultdict(list) | |
14 | |
15 for line in lines: | |
16 table[line[0].upper()].append(line) | |
17 | |
18 rows = [] | |
19 for key, value in table.items(): | |
20 rows.append("{} | {}".format(key, ", ".join(value))) | |
21 tbody = "\n".join(rows) | |
22 | |
23 with open(README_FILE, "r") as f: | |
24 content = f.read() | |
25 | |
26 with open(README_FILE, "w") as f: | |
27 marker = re.compile(r"(?P<start>:----: \\| --------\n).*?(?P<end>\n\n)", re.DOTALL) | |
28 replacement = r"\g<start>%s\g<end>" % tbody | |
29 updated_content = marker.sub(replacement, content) | |
30 f.write(updated_content) | |
31 | |
32 print(tbody) |