Fix class names on highlighted elements

This commit is contained in:
Rodrigo Fernandes 2016-05-09 10:42:00 +01:00
parent affd71eca0
commit 719b1cde71
No known key found for this signature in database
GPG key ID: 08E3C5F38969078E

View file

@ -89,7 +89,14 @@
resultNode.innerHTML = result.value;
result.value = mergeStreams(originalStream, nodeStream(resultNode), text);
}
$(line).html(result.value);
var $line = $(line);
buildClassName(line.className, result.language)
.split(" ")
.map(function(className) {
$line.addClass(className);
});
$line.html(result.value);
});
});
};
@ -181,6 +188,20 @@
* Will be removed when this part of the API is exposed
*/
function buildClassName(prevClassName, language) {
var result = [prevClassName.trim()];
if (!prevClassName.match(/\bhljs\b/)) {
result.push('hljs');
}
if (prevClassName.indexOf(language) === -1) {
result.push(language);
}
return result.join(' ').trim();
}
/* Utility functions */
function escape(value) {