From bc2c83aa7ec729f72b9067a27dae64f0bc1f4c1d Mon Sep 17 00:00:00 2001 From: Jason Yu Date: Mon, 23 Apr 2018 16:49:58 +0100 Subject: [PATCH] fix: fix emoji not showing on sidebars (#206) --- 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 df0d800c2f..2a1ed48099 100644 --- a/docs/guide/markdown.md +++ b/docs/guide/markdown.md @@ -112,7 +112,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 30f6cca9d9..5f6bf82ca5 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.data.title) { - return frontmatter.data.title + return parseEmojis(frontmatter.data.title) } const match = frontmatter.content.trim().match(/^#+\s+(.*)/) if (match) { - return match[1] + return parseEmojis(match[1]) } } @@ -65,7 +70,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),