Update markdown format

add back to top links
add some descriptions
This commit is contained in:
Ika 2017-03-18 01:33:26 +08:00
parent f667d30e60
commit 632aae66e0
2 changed files with 14 additions and 7 deletions

View File

@ -36,6 +36,6 @@ request.get(url, (error, response, body) => {
} else {
fs.mkdirSync(outDir);
}
fs.writeFileSync(outFile, markdown.create(title, emojiTable, columnDivisions));
fs.writeFileSync(outFile, markdown.create(url, title, emojiTable, columnDivisions));
}
});

View File

@ -2,17 +2,24 @@ const format = str => str.trim().replace(/^ +/mg, '');
module.exports = class Markdown {
static create(title, emojiTable, columnDivisions) {
static create(url, title, emojiTable, columnDivisions) {
const emojiCatalogs = Object.keys(emojiTable);
return format(`
# ${title}
This cheat sheet is auto-generated from <${url}> using [emoji-cheat-sheet-generator](https://github.com/ikatyang/emoji-cheat-sheet/tree/master).
## Table of Contents
${emojiCatalogs.map(catalog => `- [${catalog}](#${catalog.toLowerCase()})`).join('\n')}
${
Object.keys(emojiTable).map(catalog => {
emojiCatalogs.map(catalog => {
const emojis = emojiTable[catalog];
return format(`
#### ${catalog}
## ${catalog}
${this.createTable(emojis, columnDivisions)}
@ -26,8 +33,8 @@ module.exports = class Markdown {
static createTableHead(columnDivisions) {
return format(`
|${(' icon | emoji |').repeat(columnDivisions)}
|${(' ---- | ----- |').repeat(columnDivisions)}
| |${(' icon | emoji |').repeat(columnDivisions)}
| - |${(' ---- | ----- |').repeat(columnDivisions)}
`);
}
@ -40,7 +47,7 @@ module.exports = class Markdown {
rowEmojis.push('');
table += format(`
|${rowEmojis.map((emoji) => ` :${emoji}: | \`:${emoji}:\` `).join(' | ')}|
| [](#table-of-contents) |${rowEmojis.map((emoji) => ` :${emoji}: | \`:${emoji}:\` `).join(' | ')}|
`) + '\n';
}