2022-02-19 13:59:43 +01:00
|
|
|
const fs = require('fs');
|
2022-02-21 21:11:31 +01:00
|
|
|
const decode = require('decode-html');
|
|
|
|
const { parse } = require('node-html-parser');
|
2022-02-19 13:59:43 +01:00
|
|
|
|
|
|
|
function formatEmoji(emoji) {
|
2022-02-21 21:11:31 +01:00
|
|
|
return (
|
|
|
|
'{ name = "' + emoji.name +
|
|
|
|
'", unicode = "' + emoji.unicode +
|
|
|
|
'", tags = [ ' + emoji.tags.map(x => '"' + x + '"').join(', ') +
|
|
|
|
' ] }'
|
|
|
|
);
|
2022-02-19 13:59:43 +01:00
|
|
|
}
|
|
|
|
|
2022-02-21 21:11:31 +01:00
|
|
|
let html = parse(fs.readFileSync('js/emoji.html', 'utf-8'));
|
|
|
|
let table = html.getElementsByTagName('table')[0];
|
|
|
|
|
2022-02-19 13:59:43 +01:00
|
|
|
let emojis = {};
|
|
|
|
let currentEmojis = null;
|
|
|
|
|
2022-02-21 21:11:31 +01:00
|
|
|
for (let element of table.childNodes) {
|
|
|
|
// Skip text
|
|
|
|
if (element.nodeType === 3) continue;
|
|
|
|
|
|
|
|
if (element.rawTagName === 'tr') {
|
|
|
|
let cols = element.childNodes.filter(x => x.nodeType !== 3);
|
|
|
|
let firstCol = cols[0];
|
|
|
|
|
|
|
|
if (firstCol.classList.contains('bighead')) {
|
|
|
|
let name = decode(firstCol.childNodes.filter(x => x.nodeType !== 3)[0].childNodes[0]._rawText)
|
|
|
|
.split(' ')[0]
|
|
|
|
.toLowerCase();
|
|
|
|
|
|
|
|
currentEmojis = [];
|
|
|
|
emojis[name] = currentEmojis;
|
2022-02-19 13:59:43 +01:00
|
|
|
}
|
|
|
|
|
2022-02-21 21:11:31 +01:00
|
|
|
if (firstCol.rawTagName === 'td') {
|
|
|
|
// We're in an emoji line
|
|
|
|
let name = decode(cols[3].childNodes[0]._rawText);
|
|
|
|
let tags = decode(cols[4].childNodes[0]._rawText).split('|').map(x => x.trim());
|
|
|
|
let unicode = cols[2].childNodes[0].childNodes[0].rawAttrs.split("'")[1];
|
|
|
|
currentEmojis.push({
|
|
|
|
unicode, name, tags
|
|
|
|
});
|
|
|
|
}
|
2022-02-19 13:59:43 +01:00
|
|
|
|
2022-02-21 21:11:31 +01:00
|
|
|
}
|
2022-02-19 13:59:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
delete(emojis.component);
|
|
|
|
|
|
|
|
// Generate elm
|
|
|
|
|
|
|
|
console.log('module Emoji exposing (..)');
|
|
|
|
console.log('\n');
|
|
|
|
|
|
|
|
console.log('type alias Emoji =');
|
|
|
|
console.log(' { name : String');
|
|
|
|
console.log(' , unicode : String');
|
2022-02-21 21:11:31 +01:00
|
|
|
console.log(' , tags : List String');
|
2022-02-19 13:59:43 +01:00
|
|
|
console.log(' }');
|
|
|
|
console.log('\n');
|
|
|
|
|
|
|
|
console.log('type alias Emojis =');
|
|
|
|
let first = true;
|
|
|
|
for (let key in emojis) {
|
|
|
|
console.log(' ' + (first ? '{' : ',') + ' ' + key + ' : List Emoji');
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
console.log(' }')
|
|
|
|
console.log('\n');
|
|
|
|
|
|
|
|
console.log('type Category');
|
|
|
|
first = true;
|
|
|
|
for (let key in emojis) {
|
|
|
|
console.log(' ' + (first ? '=' : '|') + ' ' + key[0].toUpperCase() + key.slice(1).toLowerCase());
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
console.log('\n');
|
|
|
|
|
|
|
|
console.log('categories : List Category');
|
|
|
|
console.log('categories =');
|
|
|
|
console.log(' [' + Object.keys(emojis).map(x => x[0].toUpperCase() + x.slice(1).toLowerCase()).join(', ') + ']');
|
|
|
|
console.log('\n');
|
|
|
|
|
|
|
|
console.log('categoryEmoji : Category -> Emoji');
|
|
|
|
console.log('categoryEmoji category =');
|
|
|
|
console.log(' case category of');
|
|
|
|
|
|
|
|
for (let key in emojis) {
|
|
|
|
console.log(' ' + key[0].toUpperCase() + key.slice(1).toLowerCase() + ' ->');
|
|
|
|
console.log(' ' + formatEmoji(emojis[key][0]) + '\n');
|
|
|
|
}
|
|
|
|
console.log();
|
|
|
|
|
|
|
|
console.log('getEmojis : Category -> List Emoji')
|
|
|
|
console.log('getEmojis category =');
|
|
|
|
console.log(' case category of');
|
|
|
|
|
|
|
|
for (let key in emojis) {
|
|
|
|
console.log(' ' + key[0].toUpperCase() + key.slice(1).toLowerCase() + ' ->');
|
|
|
|
console.log(' emojis.' + key + '\n');
|
|
|
|
}
|
|
|
|
console.log();
|
|
|
|
|
|
|
|
console.log('emojis : Emojis');
|
|
|
|
console.log('emojis =');
|
|
|
|
let first1 = true;
|
|
|
|
|
|
|
|
for (let key in emojis) {
|
|
|
|
console.log(' ' + (first1 ? '{' : ',') + ' ' + key + ' =');
|
|
|
|
let first2 = true;
|
|
|
|
for (let emoji of emojis[key]) {
|
|
|
|
console.log(' ' + (first2 ? '[' : ',') + ' ' + formatEmoji(emoji));
|
|
|
|
first2 = false;
|
|
|
|
}
|
|
|
|
console.log(' ]');
|
|
|
|
first1 = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(' }');
|