Add line numbers to code block

This commit is contained in:
Igor Támara 2025-11-04 22:34:22 -05:00 committed by CJ van den Berg
parent 2d655ef7a4
commit 0cf7a4ead5
3 changed files with 46 additions and 11 deletions

View file

@ -6,22 +6,25 @@
--light-red: #e06c75; --light-red: #e06c75;
--dark-red: #be5046; --dark-red: #be5046;
--comment-gray: #5c6370; --comment-gray: #5c6370;
--green-light: #c678dd; --dark-green: #3c2330;
--fucsia-light: #c678dd;
--comment-color: var(--comment-gray); --comment-color: var(--comment-gray);
--string-color: var(--text-color); --string-color: var(--text-color);
--variable-color: var(--light-yellow); --variable-color: var(--light-yellow);
--field-color: var(--light-yellow); --field-color: var(--light-yellow);
--keyword-function-color: var(--text-color-accent); --keyword-function-color: var(--text-color-accent);
--keyword-color: var(--green-light); --keyword-color: var(--fucsia-light);
--keyword-modifier-color: var(--light-red); --keyword-modifier-color: var(--light-red);
--punctuation-bracket-color: var(--cyan); --punctuation-bracket-color: var(--cyan);
--type-color: var(--light-red); --type-color: var(--light-red);
--variable-parameter-color: var(--blue); --variable-parameter-color: var(--blue);
--function-call-color: var(--blue); --function-call-color: var(--blue);
---builtin-color: var(--green-light); ---builtin-color: var(--fucsi-light);
--operator-color: var(--light-red); --operator-color: var(--light-red);
--qualifier-color: var(--light-red); --qualifier-color: var(--light-red);
--attribute-color: var(--light-red); --attribute-color: var(--light-red);
--line-number-color: var(--dark-green);
--line-number-hover-color: var(--dark-yellow);
} }
code .comment { code .comment {
@ -79,3 +82,32 @@ code.zig .qualifier {
code.zig .attribute { code.zig .attribute {
color: var(--attribute-color); color: var(--attribute-color);
} }
.line-numbers-js {
/* Initialize CSS counter for each specific pre block */
counter-reset: line;
}
.line-numbers-js span.ln {
display: block;
line-height: 0;
}
.line-numbers-js span.ln:hover::before {
color: var(--line-number-hover-color);
}
.line-numbers-js span.ln::before {
/* Increment the 'line' counter for every span encountered */
counter-increment: line;
content: counter(line);
position: absolute;
right: 30px;
width: 20px;
text-align: right;
color: var(--line-number-color);
/* Prevent copying line number when selecting */
-webkit-user-select: none;
user-select: none;
}

View file

@ -113,12 +113,13 @@ pub const goto_line_meta: Meta = .{ .arguments = &.{.integer} };
and to actually receiving the integer parameter, `goto_line` will and to actually receiving the integer parameter, `goto_line` will
extract from the context like this: extract from the context like this:
```zig >[]($block.attrs('line-numbers-js'))
pub fn goto_line(self: *Self, ctx: Context) Result { >```zig
var line: usize = 0; >pub fn goto_line(self: *Self, ctx: Context) Result {
if (!try ctx.args.match(.{tp.extract(&line)})) > var line: usize = 0;
return error.InvalidGotoLineArgument; > if (!try ctx.args.match(.{tp.extract(&line)}))
``` > return error.InvalidGotoLineArgument;
>```
To send a parameter to a command, make sure that the type is exactly To send a parameter to a command, make sure that the type is exactly
the same when retrieving it. We will refer as encode and decode when the same when retrieving it. We will refer as encode and decode when

View file

@ -23,6 +23,8 @@
<ctx about="$site.page('community')"><a href="$ctx.about.link()"><i class="nf nf-fa-people_carry_box"></i></a> <a href="$ctx.about.link()">community</a></ctx> <ctx about="$site.page('community')"><a href="$ctx.about.link()"><i class="nf nf-fa-people_carry_box"></i></a> <a href="$ctx.about.link()">community</a></ctx>
</nav> </nav>
<script src="$site.asset('js/index.js').link()"></script> <script src="$site.asset('js/index.js').link()"></script>
<script src="$site.asset('js/highlight.js').link()"></script>
<script>document.addEventListener('DOMContentLoaded', addLineNumbersRobust);</script>
<super> <super>
</body> </body>
</html> </html>