flow-website/assets/js/highlight.js
Igor Támara b82a5076bd style: add line numbering
Used only on editor, not visible, needs fix on top-padding and
bottom-padding
2025-11-17 21:27:20 +01:00

22 lines
704 B
JavaScript

function addLineNumbersToPre() {
const preElements = document.querySelectorAll('div.line-numbers-js pre ');
preElements.forEach(pre => {
const codeBlock = pre.querySelector('code');
if (!codeBlock) return;
const htmlContent = codeBlock.innerHTML;
const lines = htmlContent.split('\n');
const fragment = document.createDocumentFragment();
lines.forEach(lineHtml => {
if (lineHtml.length > 0) {
const lineWrapper = document.createElement('span');
lineWrapper.className = "ln";
lineWrapper.innerHTML = lineHtml;
fragment.appendChild(lineWrapper);
}
});
codeBlock.innerHTML = '';
codeBlock.appendChild(fragment);
});
}