Skip to content

Commit

Permalink
fix: fix emoji not showing on sidebars (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
ycmjason authored and yyx990803 committed Apr 23, 2018
1 parent a16a5b4 commit bc2c83a
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 @@ -112,7 +112,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.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])
}
}

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

0 comments on commit bc2c83a

Please sign in to comment.