From c96bdabc93a7e03dac2fd3d422548f435e94e7f9 Mon Sep 17 00:00:00 2001 From: Jason Yu Date: Sun, 22 Apr 2018 15:10:39 +0100 Subject: [PATCH] fixing emoji not showing on sidebars --- docs/guide/markdown.md | 2 +- lib/util/index.js | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/docs/guide/markdown.md b/docs/guide/markdown.md index e6b00034e1..5d725f4c05 100644 --- a/docs/guide/markdown.md +++ b/docs/guide/markdown.md @@ -67,7 +67,7 @@ meta: | col 2 is | centered | $12 | | zebra stripes | are neat | $1 | -## Emoji +## Emoji :tada: **Input** diff --git a/lib/util/index.js b/lib/util/index.js index bfa48e24cf..4e368c8662 100644 --- a/lib/util/index.js +++ b/lib/util/index.js @@ -1,3 +1,8 @@ +const parseEmojis = str => { + const emojiData = require('markdown-it-emoji/lib/data/full.json') + return str.replace(/:(.+):/g, (placeholder, key) => emojiData[key] || placeholder) +} + exports.normalizeHeadTag = tag => { if (typeof tag === 'string') { tag = [tag] @@ -30,11 +35,11 @@ exports.inferTitle = function (frontmatter) { return 'Home' } if (frontmatter.title) { - return frontmatter.title + return parseEmojis(frontmatter.title) } const match = frontmatter.__content.trim().match(/^#+\s+(.*)/) if (match) { - return match[1] + return parseEmojis(match[1]) } } @@ -58,7 +63,7 @@ exports.extractHeaders = (content, include = [], md) => { const res = [] tokens.forEach((t, i) => { if (t.type === 'heading_open' && include.includes(t.tag)) { - const title = tokens[i + 1].content + const title = parseEmojis(tokens[i + 1].content) const slug = t.attrs.find(([name]) => name === 'id')[1] res.push({ level: parseInt(t.tag.slice(1), 10),