Fix code block highlighting html not escaped when no languages specified

This commit is contained in:
Wu Cheng-Han 2016-10-17 17:54:58 +08:00
parent 5e72a69d18
commit fe912f73ec

View file

@ -449,13 +449,16 @@ function finishView(view) {
var langDiv = $(value).find('code.hljs'); var langDiv = $(value).find('code.hljs');
if (langDiv.length > 0) { if (langDiv.length > 0) {
var reallang = langDiv[0].className.replace(/hljs|wrap/g, '').trim(); var reallang = langDiv[0].className.replace(/hljs|wrap/g, '').trim();
if (!reallang) return;
var codeDiv = $(value).find('.code'); var codeDiv = $(value).find('.code');
var code = ""; var code = "";
if (codeDiv.length > 0) code = codeDiv.html(); if (codeDiv.length > 0) code = codeDiv.html();
else code = langDiv.html(); else code = langDiv.html();
code = md.utils.unescapeAll(code); code = md.utils.unescapeAll(code);
if (reallang == "tiddlywiki" || reallang == "mediawiki") { if (!reallang) {
var result = {
value: md.utils.escapeHtml(code)
};
} else if (reallang == "tiddlywiki" || reallang == "mediawiki") {
var result = { var result = {
value: Prism.highlight(code, Prism.languages.wiki) value: Prism.highlight(code, Prism.languages.wiki)
}; };