Fix render emojis
This commit is contained in:
parent
6d42c6b04a
commit
11f77cd434
3 changed files with 17 additions and 6 deletions
|
|
@ -1,3 +1,7 @@
|
|||
## 1.10.1
|
||||
### Bug fixes
|
||||
- Fix render emojis
|
||||
|
||||
## 1.10.0
|
||||
### Features
|
||||
- Support emoji :laughing:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import marked from 'marked'
|
|||
import Prism from 'prismjs'
|
||||
import * as tpl from './tpl'
|
||||
import * as event from './event'
|
||||
import { genTree, getRoute, isMobile, slugify, merge } from './util'
|
||||
import { genTree, getRoute, isMobile, slugify, merge, emojify } from './util'
|
||||
|
||||
let OPTIONS = {}
|
||||
let markdown = marked
|
||||
|
|
@ -45,7 +45,7 @@ export function init (options) {
|
|||
renderer.code = function (code, lang = '') {
|
||||
const hl = Prism.highlight(code, Prism.languages[lang] || Prism.languages.markup)
|
||||
|
||||
return `<pre v-pre data-lang="${lang}"><code class="lang-${lang}">${hl}</code></pre>`
|
||||
return `<pre v-pre data-lang="${lang}"><code class="lang-${lang}">${hl.replace(/:/g, '__colon__')}</code></pre>`
|
||||
}
|
||||
renderer.link = function (href, title, text) {
|
||||
if (OPTIONS.router && !/:/.test(href)) {
|
||||
|
|
@ -63,16 +63,16 @@ export function init (options) {
|
|||
return `<p>${text}</p>`
|
||||
}
|
||||
|
||||
renderer.text = function (text) {
|
||||
return text.replace(/:(\S*?):/ig, '<img class="emoji" src="https://assets-cdn.github.com/images/icons/emoji/$1.png" alt="$1" />')
|
||||
}
|
||||
|
||||
if (typeof OPTIONS.markdown === 'function') {
|
||||
markdown.setOptions({ renderer })
|
||||
markdown = OPTIONS.markdown.call(this, markdown)
|
||||
} else {
|
||||
markdown.setOptions(merge({ renderer }, OPTIONS.markdown))
|
||||
}
|
||||
|
||||
const md = markdown
|
||||
|
||||
markdown = text => emojify(md(text))
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -157,3 +157,10 @@ export const merge = Object.assign || function (to) {
|
|||
|
||||
return to
|
||||
}
|
||||
|
||||
export function emojify (text) {
|
||||
return text
|
||||
.replace(/:(\S*?):/ig, '<img class="emoji" src="https://assets-cdn.github.com/images/icons/emoji/$1.png" alt="$1" />')
|
||||
.replace(/__colon__/g, ':')
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue