Fix class names on highlighted elements
This commit is contained in:
parent
affd71eca0
commit
719b1cde71
1 changed files with 22 additions and 1 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue