Skip to content

Commit 14a817d

Browse files
committed
Tags + some UCD filtering
1 parent 6817bf6 commit 14a817d

File tree

2 files changed

+72
-27
lines changed

2 files changed

+72
-27
lines changed

bin/ucd_to_json.ts

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ type SearchEntry = {
1414
age: string;
1515
block: string;
1616
category: string;
17+
script: string;
18+
tags?: string[];
1719
}
1820

1921
type SearchData = {
@@ -44,15 +46,58 @@ async function main() {
4446
});
4547
const jsonObj = parser.parse(xmlData);
4648

49+
console.log(`INFO: parsed ${jsonObj.ucd.repertoire.char.length} characters`);
50+
51+
if (true) {
52+
fs.writeFile(
53+
path.join(__dirname, "..", "tmp", "ucd.all.flat.json"),
54+
JSON.stringify(jsonObj, null, 2),
55+
"utf-8"
56+
);
57+
}
58+
59+
console.log(`INFO: generating JSON data`);
4760
const entries: SearchEntry[] = [];
4861

4962
for (const charData of jsonObj.ucd.repertoire.char) {
63+
64+
if (!charData.cp || charData.cp.length === 0) {
65+
if (!charData['first-cp']) { // some private use area ranges mixed in
66+
console.log(`WARN: skipping entry with no code point (${JSON.stringify(charData)})`);
67+
}
68+
continue;
69+
}
70+
71+
const tags: string[] = [];
72+
if (charData.WSpace === 'Y') {
73+
tags.push('Whitespace');
74+
}
75+
if (charData.Emoji === 'Y') {
76+
tags.push('Emoji');
77+
}
78+
if (charData.Dep === 'Y') {
79+
tags.push('Deprecated');
80+
}
81+
if (charData.QMark === 'Y') {
82+
tags.push('Quote');
83+
}
84+
if (charData.Dash === 'Y') {
85+
tags.push('Dash');
86+
}
87+
88+
var name = charData.na || charData.na1;
89+
if (!name && charData['name-alias']) {
90+
name = charData['name-alias'][0].alias;
91+
}
92+
5093
entries.push({
5194
code: charData.cp,
52-
name: charData.na || charData.na1,
95+
name: name || "(no name)",
5396
age: charData.age,
54-
block: charData.blk,
97+
block: charData.blk.replaceAll('_', ' '),
5598
category: charData.gc,
99+
script: charData.sc,
100+
tags: tags.length ? tags : undefined,
56101
});
57102
}
58103

src/index.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type SearchEntry = {
2323
age: string;
2424
block: string;
2525
category: string;
26+
tags?: string[];
2627
};
2728

2829
type SearchData = {
@@ -151,6 +152,27 @@ function fmtExampleString(cell: CellComponent) {
151152
return String.fromCodePoint(...codepoints);
152153
}
153154

155+
function fmtTags(cell: CellComponent) {
156+
const tags = cell.getValue() as string[];
157+
if (!tags || tags.length === 0) {
158+
return "";
159+
}
160+
161+
const container = document.createElement("div");
162+
163+
const keys = tags.sort();
164+
165+
for (const key of keys) {
166+
var el = document.createElement("span");
167+
el.className =
168+
"badge border border-primary text-primary me-1 mb-1 text-decoration-none";
169+
el.textContent = key;
170+
container.appendChild(el);
171+
}
172+
173+
return container;
174+
}
175+
154176
function imgTooltipFn(imgType: string) {
155177
return function (e: MouseEvent, cell: CellComponent, onRendered: any) {
156178
var value = cell.getValue();
@@ -189,28 +211,6 @@ function showError(msg: string) {
189211
document.getElementById("errmsg")!.innerHTML = msg;
190212
}
191213

192-
function tagFormatter(cell: CellComponent) {
193-
const tags = cell.getValue() as Map<string, string>;
194-
if (!tags || tags.size === 0) {
195-
return "";
196-
}
197-
198-
const container = document.createElement("div");
199-
200-
const keys = Array.from(tags.keys()).sort();
201-
202-
for (const key of keys) {
203-
const value = tags.get(key) || "";
204-
var el = document.createElement("a");
205-
el.href = value;
206-
el.className = "badge border border-primary text-primary me-1 mb-1 text-decoration-none";
207-
el.target = "_blank";
208-
el.textContent = key;
209-
container.appendChild(el);
210-
}
211-
212-
return container;
213-
}
214214

215215
const tickElement = `<svg enable-background="new 0 0 24 24" height="14" width="14" viewBox="0 0 24 24" xml:space="preserve"><path fill="#2DC214" clip-rule="evenodd" d="M21.652,3.211c-0.293-0.295-0.77-0.295-1.061,0L9.41,14.34 c-0.293,0.297-0.771,0.297-1.062,0L3.449,9.351C3.304,9.203,3.114,9.13,2.923,9.129C2.73,9.128,2.534,9.201,2.387,9.351 l-2.165,1.946C0.078,11.445,0,11.63,0,11.823c0,0.194,0.078,0.397,0.223,0.544l4.94,5.184c0.292,0.296,0.771,0.776,1.062,1.07 l2.124,2.141c0.292,0.293,0.769,0.293,1.062,0l14.366-14.34c0.293-0.294,0.293-0.777,0-1.071L21.652,3.211z" fill-rule="evenodd"></path></svg>`;
216216

@@ -380,15 +380,15 @@ async function main() {
380380
{
381381
title: "Tags",
382382
field: "tags",
383-
formatter: tagFormatter,
383+
formatter: fmtTags,
384384
headerSort: false,
385385
responsive: 0,
386386
width: 375,
387387
},
388388
],
389389
height: "100%",
390-
initialHeaderFilter: [{ field: "ar21", type: "=", value: true }],
391-
initialSort: [{ column: "sort", dir: "asc" }],
390+
//initialHeaderFilter: [{ field: "ar21", type: "=", value: true }],
391+
initialSort: [{ column: "code", dir: "asc" }],
392392
layout: "fitDataStretch",
393393
placeholder: "No matches",
394394
responsiveLayout: "hide",

0 commit comments

Comments
 (0)