author | Olivier Brunel
<jjk@jjacky.com> 2022-12-31 21:23:15 UTC |
committer | Olivier Brunel
<jjk@jjacky.com> 2022-12-31 21:23:15 UTC |
parent | c00ee90af626cf881a5b773c8508323cdb5ac707 |
base.htm | +1 | -1 |
dark.css | +4 | -0 |
light.css | +4 | -0 |
main.c | +10 | -0 |
struct.css | +8 | -0 |
diff --git a/base.htm b/base.htm index 1128458..4647f39 100644 --- a/base.htm +++ b/base.htm @@ -157,7 +157,7 @@ multiple lines</span>. Yep. <p>Oh yeah, we might wanna have "code blocks". Those would be like <code>pre</code> ones, only a bit more styled : <pre class="lineno">1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9<br>10</pre> -<pre><code>#include <stdlib.h> +<pre><span>c</span><code>#include <stdlib.h> int main(int argc, char **argv) { int nb = 3; diff --git a/dark.css b/dark.css index 75b8b96..5e840f5 100644 --- a/dark.css +++ b/dark.css @@ -46,6 +46,10 @@ border: 1px solid #495457; background: #999463; } + main pre.lineno + pre > span { + background: #086abf; + color: #eee; + } main a { color: blue; } diff --git a/light.css b/light.css index e9e9bed..367b0ac 100644 --- a/light.css +++ b/light.css @@ -44,6 +44,10 @@ main pre { border: 1px solid #e1e4e5; background: #f2ecb7; } +main pre.lineno + pre > span { + background: #217ed0; + color: #eee; +} main a { color: blue; } diff --git a/main.c b/main.c index c4cc274..110df56 100644 --- a/main.c +++ b/main.c @@ -612,9 +612,16 @@ leave_block(MD_BLOCKTYPE type, void *details, void *ctx_) BUFFERING_OFF(buf, blen); if (ctx->code.flags & CODE_LINES) { + MD_BLOCK_CODE_DETAIL *d = details; const char *s = buf; size_t l = blen; + const char *e; + size_t codelen; + + e = memchr(d->info.text, ' ', d->info.size); + codelen = (e) ? e - d->info.text : d->info.size; + if (!raw_str(ctx, "<pre class=\"lineno\">")) return ERR_PARSER_BUFFERED; for (int n = ctx->code.from; s; ++n) { @@ -628,6 +635,9 @@ leave_block(MD_BLOCKTYPE type, void *details, void *ctx_) return ERR_PARSER_BUFFERED; } if (!raw_str(ctx, "</pre>") || !raw_str(ctx, "<pre>") + || !raw_str(ctx, "<span>") + || !escape_text(ctx, d->info.text, codelen) + || !raw_str(ctx, "</span>") || !raw_str(ctx, "<code>")) return ERR_PARSER_BUFFERED; } else { diff --git a/struct.css b/struct.css index 172296b..658cd1d 100644 --- a/struct.css +++ b/struct.css @@ -128,6 +128,14 @@ main pre.lineno + pre { border: none; background: none; } +main pre.lineno + pre > span { + position: absolute; + left: 55px; + margin-top: -2px; + padding: 0 23px; + font-weight: 600; + font-size: 90%; +} main pre code { display: block; padding: 0;