1 回答

TA贡献1772条经验 获得超8个赞
var converter = new showdown.Converter({extensions: function() {
function htmlunencode(text) {
return (
text
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
);
}
return [
{
type: 'output',
filter: function (text, converter, options) {
// use new shodown's regexp engine to conditionally parse codeblocks
var left = '<pre><code\\b[^>]*>',
right = '</code></pre>',
flags = 'g',
replacement = function (wholeMatch, match, left, right) {
// unescape match to prevent double escaping
match = htmlunencode(match);
return left + hljs.highlightAuto(match).value + right;
};
return showdown.helper.replaceRecursiveRegExp(text, replacement, left, right, flags);
}
}
];
}()});
比较粗暴地把后面的匿名函数当成参数传入,就可以实现了。
添加回答
举报