mirror of https://gitlab.com/curben/blog
fix(smartypants): utilise escapeHTML()
- breaking change of marked v4 * https://github.com/markedjs/marked/releases/tag/v4.0.0
This commit is contained in:
parent
834a75bba0
commit
4fca3c6cf9
|
@ -1,4 +1,4 @@
|
||||||
const { escape } = require('marked/src/helpers');
|
const { escapeHTML: escape } = require('hexo-util')
|
||||||
|
|
||||||
// https://github.com/markedjs/marked/blob/b6773fca412c339e0cedd56b63f9fa1583cfd372/src/Lexer.js#L8-L24
|
// https://github.com/markedjs/marked/blob/b6773fca412c339e0cedd56b63f9fa1583cfd372/src/Lexer.js#L8-L24
|
||||||
// Replace dashes only
|
// Replace dashes only
|
||||||
|
@ -19,22 +19,22 @@ const smartypants = (str) => {
|
||||||
// ellipses
|
// ellipses
|
||||||
.replace(/\.{3}/g, '\u2026')
|
.replace(/\.{3}/g, '\u2026')
|
||||||
// right arrow
|
// right arrow
|
||||||
.replace(/->/g, '\u2192');
|
.replace(/->/g, '\u2192')
|
||||||
};
|
}
|
||||||
|
|
||||||
hexo.extend.filter.register('marked:tokenizer', function(tokenizer) {
|
hexo.extend.filter.register('marked:tokenizer', function (tokenizer) {
|
||||||
const { smartypants: isSmarty } = this.config.marked;
|
const { smartypants: isSmarty } = this.config.marked
|
||||||
tokenizer.inlineText = function(src) {
|
tokenizer.inlineText = function (src) {
|
||||||
const { rules } = this;
|
const { rules } = this
|
||||||
|
|
||||||
// https://github.com/markedjs/marked/blob/b6773fca412c339e0cedd56b63f9fa1583cfd372/src/Tokenizer.js#L643-L658
|
// https://github.com/markedjs/marked/blob/b6773fca412c339e0cedd56b63f9fa1583cfd372/src/Tokenizer.js#L643-L658
|
||||||
const cap = rules.inline.text.exec(src);
|
const cap = rules.inline.text.exec(src)
|
||||||
if (cap) {
|
if (cap) {
|
||||||
let text;
|
let text
|
||||||
if (this.lexer.state.inRawBlock) {
|
if (this.lexer.state.inRawBlock) {
|
||||||
text = cap[0];
|
text = cap[0]
|
||||||
} else {
|
} else {
|
||||||
text = escape(isSmarty ? smartypants(cap[0]) : cap[0]);
|
text = escape(isSmarty ? smartypants(cap[0]) : cap[0])
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
// `type` value is a corresponding renderer method
|
// `type` value is a corresponding renderer method
|
||||||
|
@ -42,7 +42,7 @@ hexo.extend.filter.register('marked:tokenizer', function(tokenizer) {
|
||||||
type: 'text',
|
type: 'text',
|
||||||
raw: cap[0],
|
raw: cap[0],
|
||||||
text
|
text
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
})
|
||||||
|
|
Loading…
Reference in New Issue