2017-03-17 18:10:09 +01:00
|
|
|
const format = str => str.trim().replace(/^ +/mg, '');
|
|
|
|
|
|
|
|
module.exports = class Markdown {
|
|
|
|
|
2017-03-18 08:27:33 +01:00
|
|
|
static create(urls, title, emojiTable, columnDivisions) {
|
|
|
|
const categories = Object.keys(emojiTable);
|
|
|
|
const urlDescriptions = Object.keys(urls).map((site) => `[${site}](${urls[site]})`).join(' and ');
|
2017-03-17 18:10:09 +01:00
|
|
|
return format(`
|
|
|
|
|
|
|
|
# ${title}
|
|
|
|
|
2017-03-18 08:32:44 +01:00
|
|
|
This cheat sheet is auto-generated from ${urlDescriptions} using [emoji-cheat-sheet-generator](https://github.com/ikatyang/emoji-cheat-sheet/tree/generator).
|
2017-03-17 18:33:26 +01:00
|
|
|
|
|
|
|
## Table of Contents
|
|
|
|
|
2017-03-18 08:27:33 +01:00
|
|
|
${categories.map(category => `- [${category}](#${category.toLowerCase()})`).join('\n')}
|
2017-03-17 18:33:26 +01:00
|
|
|
|
2017-03-17 18:10:09 +01:00
|
|
|
${
|
2017-03-18 08:27:33 +01:00
|
|
|
categories.map(category => {
|
|
|
|
const emojis = emojiTable[category];
|
2017-03-17 18:10:09 +01:00
|
|
|
return format(`
|
|
|
|
|
2017-03-18 08:27:33 +01:00
|
|
|
### ${category}
|
2017-03-17 18:10:09 +01:00
|
|
|
|
|
|
|
${this.createTable(emojis, columnDivisions)}
|
|
|
|
|
|
|
|
`);
|
|
|
|
}).join(('\n').repeat(2))
|
|
|
|
}
|
|
|
|
|
|
|
|
`);
|
|
|
|
}
|
|
|
|
|
|
|
|
static createTableHead(columnDivisions) {
|
|
|
|
return format(`
|
|
|
|
|
2017-03-18 08:27:33 +01:00
|
|
|
| |${(' ico | emoji |').repeat(columnDivisions)}
|
|
|
|
| - |${(' --- | ----- |').repeat(columnDivisions)}
|
2017-03-17 18:10:09 +01:00
|
|
|
|
|
|
|
`);
|
|
|
|
}
|
|
|
|
|
|
|
|
static createTable(emojis, columnDivisions) {
|
|
|
|
let table = this.createTableHead(columnDivisions) + '\n';
|
|
|
|
for (let i = 0; i < emojis.length; i += columnDivisions) {
|
|
|
|
const rowEmojis = emojis.slice(i, i + columnDivisions);
|
|
|
|
while (rowEmojis.length < columnDivisions)
|
|
|
|
rowEmojis.push('');
|
|
|
|
table += format(`
|
|
|
|
|
2017-03-18 08:27:33 +01:00
|
|
|
| [top](#table-of-contents) |${rowEmojis.map((emoji) => emoji ? ` :${emoji}: | \`:${emoji}:\` ` : ' | ').join(' | ')}|
|
2017-03-17 18:10:09 +01:00
|
|
|
|
|
|
|
`) + '\n';
|
|
|
|
}
|
|
|
|
return table;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|