Skip to content

Instantly share code, notes, and snippets.

@dmertl
Last active May 5, 2024 02:55
Show Gist options
  • Save dmertl/257433864ba85d4fcc3c128a47db34c3 to your computer and use it in GitHub Desktop.
Save dmertl/257433864ba85d4fcc3c128a47db34c3 to your computer and use it in GitHub Desktop.
Print unicode chars from names file
const SKIP_START = ['\t', '@', ';'];
const SKIP_WORDS = [
'<control>',
'<not a character>',
'MODIFIER',
'LEFT-TO-RIGHT',
'RIGHT-TO-LEFT',
'FORMATTING',
'SPACE',
'COMBINING',
'POINT ',
'MARK ',
'ACCENT ',
'JOINER',
'SEPARATOR',
'HEBREW ',
'-FACING',
'ARABIC',
'AFGHANI',
'DEVANAGARI',
'SYRIAC',
'THAANA',
'NKO',
'SAMARITAN',
'ORIYA',
'LAO ',
'FILLER',
'SUBJOINED',
'THAI CHARACTER',
'TIBETAN',
'TAGALOG',
'HANUNOO',
'BUHID',
'TAGBANWA',
'LIMBU',
'TAI THAM',
'VEDIC',
'CYPRIOT',
'MANDAIC',
'SAMARITAN',
'LINEAR A',
'TAG ',
];
const ALPHANUM = '0123456789ABCDEF';
const unicode_text = document.body.firstChild;
const container = document.createElement('div');
document.body.insertBefore(container, unicode_text);
let line_cnt = 1;
let line_str = '';
let line_p = document.createElement('p');
line_loop: for (const line of unicode_text.innerText.split("\n")) {
// console.log(line_cnt + ' ' + line);
if (!line || SKIP_START.includes(line[0])) {
// console.log('skip');
continue;
}
for (const w of SKIP_WORDS) {
if (line.includes(w)) {
continue line_loop;
}
}
if (line[0] === '0' && line[1] === '0' && ALPHANUM.includes(line[2])) {
continue;
}
let current_char_hex = line.substr(0, line.indexOf('\t'));
let current_char = String.fromCodePoint(Number('0x' + current_char_hex));
// console.log(line_cnt + ' ' + current_char_hex + ' 000 ' + current_char + ' 888 ' + line);
line_p.innerHTML += current_char;
// line_str += '&#' + current_char + ';';
if (line_cnt % 20 === 0) {
line_p.innerHTML += ' ' + current_char_hex + ' ' + line_cnt;
container.appendChild(line_p);
line_p = document.createElement('p');
line_str = '';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment