feat: remove highlight.js line numbers plugin and clean up related code
This commit is contained in:
1 parent
d87d46d9d0
commit
7906c15fa7
4 files changed
+1
-51
No files matched your search
@@ -804,39 +804,6 @@
|
||||
Array.prototype.forEach.call(codes, function (code) {
|
||||
try { window.hljs.highlightElement(code); } catch (e) {}
|
||||
});
|
||||
// Line numbers (self-hosted plugin). Skips single-line blocks by default.
|
||||
var ln = document.createElement('script');
|
||||
ln.src = BASE + 'js/highlightjs-line-numbers.min.js';
|
||||
ln.onload = function () {
|
||||
if (!window.hljs || !window.hljs.lineNumbersBlock) return;
|
||||
Array.prototype.forEach.call(codes, function (code) {
|
||||
// Drop a trailing newline so the plugin doesn't add a blank last line.
|
||||
code.innerHTML = code.innerHTML.replace(/\n+$/, '');
|
||||
try { window.hljs.lineNumbersBlock(code, { singleLine: false }); } catch (e) {}
|
||||
});
|
||||
// The plugin builds the table on a 0ms timer; clean up afterwards:
|
||||
// remove any trailing empty row and trailing whitespace nodes that
|
||||
// would leave a blank "phantom" line at the bottom of the block.
|
||||
setTimeout(function () {
|
||||
Array.prototype.forEach.call(codes, function (code) {
|
||||
var rows = code.querySelectorAll('.hljs-ln tr');
|
||||
if (rows.length) {
|
||||
var last = rows[rows.length - 1];
|
||||
var cell = last.querySelector('.hljs-ln-code');
|
||||
if (cell && cell.textContent.replace(/\s+/g, '') === '') {
|
||||
last.parentNode.removeChild(last);
|
||||
}
|
||||
}
|
||||
var n = code.lastChild;
|
||||
while (n && n.nodeType === 3 && !n.textContent.trim()) {
|
||||
var prev = n.previousSibling;
|
||||
code.removeChild(n);
|
||||
n = prev;
|
||||
}
|
||||
});
|
||||
}, 60);
|
||||
};
|
||||
document.head.appendChild(ln);
|
||||
};
|
||||
document.head.appendChild(s);
|
||||
})();
|
||||
|
||||
Reference in new issue
Block a user