Skip to content

Commit 443c289

Browse files
committed
Mapping examples for invisible characters
1 parent 35c7d71 commit 443c289

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/index.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,18 @@ const categoryMap: { [key: string]: string } = {
6969
"Zs": "Separator, Space"
7070
}
7171

72+
const exampleMap: { [key: string]: string } = {};
73+
74+
function initExampleMap(data: SearchEntry[]) {
75+
for (var loop = 0; loop <= 0x1F; loop++) {
76+
exampleMap[String.fromCodePoint(loop)] = String.fromCodePoint(0x2400 + loop);
77+
}
78+
exampleMap["<"] = "&lt;";
79+
exampleMap[">"] = "&gt;";
80+
exampleMap["&"] = "&amp;";
81+
exampleMap["\""] = "&quot;";
82+
}
83+
7284
// translates from a hex codepoint string to the actual character
7385
function codeToString(code: string):string {
7486
return String.fromCodePoint(parseInt(code, 16));
@@ -179,7 +191,9 @@ function fmtExample(cell: CellComponent) {
179191
if (!val) {
180192
return "";
181193
}
182-
return `<span style="font-size:2em;">${val}</span>`;
194+
195+
const mapped = exampleMap[val] || val;
196+
return `<span style="font-size:2em;">${mapped}</span>`;
183197
}
184198

185199
function fmtTags(cell: CellComponent) {
@@ -362,6 +376,8 @@ async function main() {
362376
row.example = codeToString(row.code);
363377
}
364378

379+
initExampleMap(data);
380+
365381
console.log(data[0]);
366382

367383
const qs = new URLSearchParams(window.location.search);

0 commit comments

Comments
 (0)