Skip to content

Commit

Permalink
fixing emoji not showing on sidebars
Browse files Browse the repository at this point in the history
  • Loading branch information
ycmjason committed Apr 22, 2018
1 parent 911b78c commit 2d3e808
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/guide/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ meta:
| col 2 is | centered | $12 |
| zebra stripes | are neat | $1 |

## Emoji
## Emoji :tada:

**Input**

Expand Down
11 changes: 8 additions & 3 deletions lib/util/index.js
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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])
}
}

Expand All @@ -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),
Expand Down

0 comments on commit 2d3e808

Please sign in to comment.