diff --git a/lib/util/highlight.js b/lib/util/highlight.js
index 293ef55..5e46369 100644
@@ -5,6 +5,19 @@ hljs.configure({
classPrefix: ''
});
+hljs.highlightByLine = function(name, value, ignore_illegals) {
+ var result = {value: ''};
+ var lines = value.split('\n');
+ var state = null;
+ lines.forEach(function(line, index) {
+ if (index !== 0) result.value += '\n';
+ var tmpRst = hljs.highlight(name, line, ignore_illegals, state);
+ state = tmpRst.top;
+ result.value += tmpRst.value;
+ });
+ return result;
+};
+
var alias = {
js: 'javascript',
jscript: 'javascript',
@@ -74,7 +87,7 @@ module.exports = function(str, options){
if (keys.indexOf(lang) !== -1) lang = alias[lang];
try {
- compiled = hljs.highlight(lang, str).value;
+ compiled = hljs.highlightByLine(lang, str).value;
} catch (e){
compiled = hljs.highlightAuto(str).value;
}
@@ -88,8 +101,12 @@ module.exports = function(str, options){
firstLine = options.first_line;
lines.forEach(function(item, i){
- numbers += '<div class="line">' + (i + firstLine) + '</div>';
- content += '<div class="line">' + item + '</div>';
+ if (i !== 0) {
+ numbers += '\n';
+ content += '\n';
+ }
+ numbers += '<span class="line">' + (i + firstLine) + '</span>';
+ content += '<span class="line">' + item + '</span>';
});
var result = '<figure class="highlight' + (options.lang ? ' ' + options.lang : '') + '">' +