Skip to content

Commit bc2c83a

Browse files
ycmjasonyyx990803
authored andcommitted
fix: fix emoji not showing on sidebars (#206)
1 parent a16a5b4 commit bc2c83a

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

docs/guide/markdown.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ meta:
112112
| col 2 is | centered | $12 |
113113
| zebra stripes | are neat | $1 |
114114

115-
## Emoji
115+
## Emoji :tada:
116116

117117
**Input**
118118

lib/util/index.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
const parseEmojis = str => {
2+
const emojiData = require('markdown-it-emoji/lib/data/full.json')
3+
return str.replace(/:(.+?):/g, (placeholder, key) => emojiData[key] || placeholder)
4+
}
5+
16
exports.normalizeHeadTag = tag => {
27
if (typeof tag === 'string') {
38
tag = [tag]
@@ -30,11 +35,11 @@ exports.inferTitle = function (frontmatter) {
3035
return 'Home'
3136
}
3237
if (frontmatter.data.title) {
33-
return frontmatter.data.title
38+
return parseEmojis(frontmatter.data.title)
3439
}
3540
const match = frontmatter.content.trim().match(/^#+\s+(.*)/)
3641
if (match) {
37-
return match[1]
42+
return parseEmojis(match[1])
3843
}
3944
}
4045

@@ -65,7 +70,7 @@ exports.extractHeaders = (content, include = [], md) => {
6570
const res = []
6671
tokens.forEach((t, i) => {
6772
if (t.type === 'heading_open' && include.includes(t.tag)) {
68-
const title = tokens[i + 1].content
73+
const title = parseEmojis(tokens[i + 1].content)
6974
const slug = t.attrs.find(([name]) => name === 'id')[1]
7075
res.push({
7176
level: parseInt(t.tag.slice(1), 10),

0 commit comments

Comments
 (0)