functionaddLineNumbersForCode(html) { var num = 1; html = '<span class="ln-num" data-num="' + num + '"></span>' + html; html = html.replace(/\r\n|\r|\n/g, function (a) { num++; return a + '<span class="ln-num" data-num="' + num + '"></span>'; }); html = '<span class="ln-bg"></span>' + html; return html; }
functiondocumentReady() { var elements = d.querySelectorAll('pre code'); for (var i = 0; i < elements.length; i++) { if (elements[i].className.indexOf('hljsln') == -1) { var html = elements[i].innerHTML; html = addLineNumbersForCode(html); elements[i].innerHTML = html; elements[i].className += ' hljsln'; } } } }(window, document));
functionaddLineNumbersForCode(html) { var num = 0; var max = 0; html = html.replace(/\r\n|\r|\n/g, function (b) { max++; if (max != 0) { return b; } }); html = html.replace(/\r\n|\r|\n/g, function (a) { num++; if (num != 0 && num != max) { return a + '<span class="ln-num" data-num="' + num + '"></span>'; }elseif (num != 0 && num == max) { return a + ' '; } }); html = '<span class="ln-bg" style="margin-left: 1px"></span>' + html; return html; }