forked from whatwg/encoding
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools-label-table.py
34 lines (30 loc) · 1.11 KB
/
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
29
30
31
32
33
34
import json
def get_data(filename):
return json.loads(open(filename, "r").read())
def create_table():
data = get_data("encodings.json")
table = ""
labelsseen = []
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 + "><span>" + encoding["name"] + "</span>"
i = 0
labels = encoding["labels"]
labels.sort()
for label in labels:
if label in labelsseen:
raise NameError("Duplicate label: " + label)
labelsseen.append(label)
if i > 0:
table += " <tr>"
else:
table += "\n "
table += "<td>\"<code title>" + label + "</code>\"\n"
i += 1
print table
create_table()