fix potential problems with highlighter callback and escapes.
This commit is contained in:
parent
b814a0af9b
commit
f7be7f9640
@ -81,9 +81,9 @@ marked.setOptions({
|
|||||||
pedantic: false,
|
pedantic: false,
|
||||||
sanitize: true,
|
sanitize: true,
|
||||||
// callback for code highlighter
|
// callback for code highlighter
|
||||||
highlight: function(code, language) {
|
highlight: function(code, lang) {
|
||||||
if (language === 'js') {
|
if (lang === 'js') {
|
||||||
code = highlight(code);
|
return javascriptHighlighter(code);
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -531,10 +531,15 @@ var tok = function() {
|
|||||||
+ '>\n';
|
+ '>\n';
|
||||||
}
|
}
|
||||||
case 'code': {
|
case 'code': {
|
||||||
|
if (options.highlight) {
|
||||||
|
token.code = options.highlight(token.text, token.lang);
|
||||||
|
if (token.code != null && token.code !== token.text) {
|
||||||
|
token.escaped = true;
|
||||||
|
token.text = token.code;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!token.escaped) {
|
if (!token.escaped) {
|
||||||
token.text = options.highlight
|
token.text = escape(token.text, true);
|
||||||
? options.highlight(token.text, token.lang)
|
|
||||||
: escape(token.text, true);
|
|
||||||
}
|
}
|
||||||
return '<pre><code'
|
return '<pre><code'
|
||||||
+ (token.lang
|
+ (token.lang
|
||||||
|
Loading…
x
Reference in New Issue
Block a user