Skip to content

Commit 1e5b27f

Browse files
committed
Script to gen dictionary list for docs.
1 parent 961a2dd commit 1e5b27f

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

generate_dict_markdown_table.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
Language dictionaries markdown table generation.
3+
"""
4+
5+
from glob import glob
6+
import os
7+
import yaml
8+
9+
def get_table_rows():
10+
"Get markdown table for docs."
11+
thisdir = os.path.dirname(__file__)
12+
langglob = os.path.join(thisdir, "**", "definition.yaml")
13+
output = []
14+
for filename in glob(langglob):
15+
with open(filename, "r", encoding="utf-8") as f:
16+
y = yaml.safe_load(f)
17+
langname = y["name"]
18+
for d in y["dictionaries"]:
19+
data = [
20+
langname,
21+
d["for"],
22+
d["type"],
23+
f"`{d['url']}`"
24+
]
25+
output.append("|" + "|".join(data) + "|")
26+
output.sort()
27+
return output
28+
29+
30+
def generate_table():
31+
"Gen table"
32+
print("|Language|For|Type|URL|")
33+
print("|---|---|---|---|")
34+
rows = get_table_rows()
35+
print("\n".join(rows))
36+
37+
38+
if __name__ == "__main__":
39+
generate_table()

0 commit comments

Comments
 (0)