style: add line numbering
Used only on editor, not visible, needs fix on top-padding and bottom-padding
This commit is contained in:
parent
1bb3b70864
commit
b82a5076bd
3 changed files with 24 additions and 2 deletions
|
|
@ -83,7 +83,7 @@ code.zig .attribute {
|
|||
color: var(--attribute-color);
|
||||
}
|
||||
|
||||
.line-numbers-js {
|
||||
.line-numbers-js pre code {
|
||||
/* Initialize CSS counter for each specific pre block */
|
||||
counter-reset: line;
|
||||
}
|
||||
|
|
|
|||
22
assets/js/highlight.js
Normal file
22
assets/js/highlight.js
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
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);
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue