aboutsummaryrefslogtreecommitdiff
path: root/subscript.py
blob: 1abd38fe21a0e02f5b0f49a0e3fee820368e79d4 (plain)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0-only

from sys import stderr

with open("UnicodeData.txt") as f:
    data = f.read()
data = data.split("\n")

subscripts = {}


def line_to_char(line):
    return chr(int(line.split(";", 1)[0], 16))


for line in data:
    if "SUBSCRIPT" in line:
        normal_name = ''.join(line.split(";", 2)[1].split("SUBSCRIPT ", 1))
        if normal_name == "MINUS":
            normal_name = "MINUS SIGN"
        if normal_name == "ARABIC ALEF":
            normal_name = "ARABIC LETTER ALEF"
        normal_line = None
        for line2 in data:
            if (
                (";" + normal_name + ";" in line2 or ";DIGIT " + normal_name + ";" in line2)
                and line != line2
                and "<control>" not in line2
            ):
                normal_line = line2
                break
        if not normal_line:
            print("not found:", line, file=stderr)
            continue
        char = line_to_char(line)
        normal = line_to_char(normal_line)
        if normal not in subscripts:
            subscripts[normal] = char

subscripts["-"] = subscripts["−"]
subscripts[" "] = " "

import json

print("window.unicodeMaps.toSubscript =", json.dumps(subscripts), ";")
print(subscripts, file=stderr)