forked from whatwg/encoding
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools-label-table.py
28 lines (24 loc) · 910 Bytes
/
tools-label-table.py
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
import json
def get_data(filename):
return json.loads(open(filename, "r").read())
def create_table():
data = get_data("encodings.json")
table = ""
for set in data:
table += " <tbody>\n <tr><th colspan=2><a href=#" + set["heading"].lower().replace(" ", "-") + ">" + set["heading"] + "</a>\n"
for encoding in set["encodings"]:
rowspan = ""
label_len = len(encoding["labels"])
if label_len > 1:
rowspan = " rowspan=" + str(label_len)
table += " <tr>\n <td" + rowspan + "><a>" + encoding["name"] + "</a>"
i = 0
for label in encoding["labels"]:
if i > 0:
table += " <tr>"
else:
table += "\n "
table += "<td>\"<code>" + label + "</code>\"\n"
i += 1
print(table)
create_table()