mirror of
https://github.com/amehime/hexo-renderer-multi-markdown-it.git
synced 2026-04-05 04:59:04 +08:00
fix
This commit is contained in:
@@ -2,6 +2,9 @@ const Prism = require('prismjs');
|
||||
const loadLanguages = require('prismjs/components/');
|
||||
const pangu = require('pangu');
|
||||
const LanguagesTip = require('./lang');
|
||||
const { escapeHTML, unescapeHTML } = require('hexo-util');
|
||||
const escapeSwigTag = str => str.replace(/{/g, '{').replace(/}/g, '}');
|
||||
const unescapeSwigTag = str => str.replace(/{/g, '{').replace(/}/g, '}');
|
||||
|
||||
loadLanguages.silent = true;
|
||||
|
||||
@@ -48,7 +51,7 @@ module.exports = function (md, options) {
|
||||
const token = tokens[idx]
|
||||
const info = token.info
|
||||
const text = token.content.trim()
|
||||
const lang = info.split(" ")[0]
|
||||
const lang = info.trim().split(" ")[0]
|
||||
var code = null
|
||||
|
||||
let [langToUse, langShow, prismLang] = selectLanguage(config, lang);
|
||||
@@ -61,13 +64,14 @@ module.exports = function (md, options) {
|
||||
} = getOptions(info.slice(lang.length));
|
||||
|
||||
if (prismLang) {
|
||||
code = Prism.highlight(text.replace(/{/g, '{').replace(/}/g, '}'), prismLang, langToUse).replace(/{/g, '{').replace(/}/g, '}');
|
||||
code = Prism.highlight(unescapeSwigTag(text), prismLang, langToUse);
|
||||
} else if(lang == 'raw') {
|
||||
code = pangu.spacing(text);
|
||||
code = escapeHTML(pangu.spacing(unescapeSwigTag(text)));
|
||||
langShow = null;
|
||||
}
|
||||
|
||||
if(code) {
|
||||
code = escapeSwigTag(code);
|
||||
const lines = code.split('\n');
|
||||
|
||||
let content = '';
|
||||
@@ -103,7 +107,7 @@ module.exports = function (md, options) {
|
||||
}
|
||||
|
||||
if (lang == 'info') {
|
||||
return `<pre class="info"><code>${pangu.spacing(text)}</code></pre>`;
|
||||
return `<pre class="info"><code>${escapeHTML(pangu.spacing(unescapeSwigTag(text)))}</code></pre>`;
|
||||
} else {
|
||||
return defaultRenderer(tokens, idx, options, env, self);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hexo-renderer-multi-markdown-it",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"description": "A Markdown parser for Hexo and auto Minify HTML, CSS, JS.",
|
||||
"main": "index.js",
|
||||
"repository": "https://github.com/amehime/hexo-renderer-multi-markdown-it.git",
|
||||
|
||||
Reference in New Issue
Block a user