Skip to content

Commit 2cc531f

Browse files
chhzh123claude
andcommitted
Add line numbers to code viewer modal
- Load highlightjs-line-numbers.js plugin lazily alongside hljs - Call hljs.lineNumbersBlock() after highlighting - Style gutter: right-aligned numbers, subtle divider, non-selectable Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 5d3de18 commit 2cc531f

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

index.html

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,16 @@
550550
font-family: 'JetBrains Mono','Fira Code','Cascadia Code','Consolas',monospace;
551551
}
552552
.cm-pre code { background: none !important; padding: 0 !important; font-size: inherit !important; }
553+
/* line-numbers plugin */
554+
.cm-pre .hljs-ln { border-collapse: collapse; width: 100%; }
555+
.cm-pre .hljs-ln td { padding: 0; }
556+
.cm-pre .hljs-ln-numbers {
557+
width: 2.8em; padding-right: 1em !important;
558+
text-align: right; vertical-align: top;
559+
color: #4a5568; border-right: 1px solid #2d2d44;
560+
user-select: none; cursor: default;
561+
}
562+
.cm-pre .hljs-ln-code { padding-left: 1em !important; }
553563
/* view-code button in table */
554564
.code-view-btn {
555565
display: inline-flex; align-items: center; gap: 0.3rem;
@@ -1417,6 +1427,7 @@ <h2>Solve Metrics (T = 0)</h2>
14171427
codeEl.textContent = code;
14181428
if (!window.hljs) await loadHljs();
14191429
hljs.highlightElement(codeEl);
1430+
hljs.lineNumbersBlock(codeEl);
14201431

14211432
const modal = document.getElementById("code-modal");
14221433
modal.classList.remove("hidden");
@@ -1451,7 +1462,12 @@ <h2>Solve Metrics (T = 0)</h2>
14511462
s.onload = () => {
14521463
const py = document.createElement("script");
14531464
py.src = "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/python.min.js";
1454-
py.onload = resolve;
1465+
py.onload = () => {
1466+
const ln = document.createElement("script");
1467+
ln.src = "https://cdnjs.cloudflare.com/ajax/libs/highlightjs-line-numbers.js/2.8.0/highlightjs-line-numbers.min.js";
1468+
ln.onload = resolve;
1469+
document.head.appendChild(ln);
1470+
};
14551471
document.head.appendChild(py);
14561472
};
14571473
document.head.appendChild(s);

0 commit comments

Comments
 (0)