stagit

static page generator for git
git clone https://github.com/michaelneuper/stagit.git
README | Files | Log | Refs | LICENSE

commit bf40c1f2315b429d1d058b19e306a729f67de515
parent dae9aafc3e4fcbf87b04fd81b808546fe9e25ff5
Author: Michael Neuper <michael@michaelneuper.com>
Date:   Sun, 25 Oct 2026 21:59:40 +0200

draw line numbers with CSS so they aren't copied with the code

Diffstat:
Mstagit.c | 3++-
Mstyle.css | 9+++++++++
2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/stagit.c b/stagit.c @@ -591,7 +591,8 @@ size_t writeblobhtml(FILE *fp, const git_blob *blob) { size_t n = 0, i, len, prev; - const char *nfmt = "<a href=\"#l%zu\" class=\"line\" id=\"l%zu\">%7zu</a> "; + /* style.css draws the number from data-n, so it isn't copied with the code */ + const char *nfmt = "<a href=\"#l%zu\" class=\"line\" id=\"l%zu\" data-n=\"%zu\"></a>"; const char *s = git_blob_rawcontent(blob); len = git_blob_rawsize(blob); diff --git a/style.css b/style.css @@ -167,9 +167,18 @@ pre { } #blob a.line { + display: inline-block; + width: 7ch; + margin-right: 1ch; + text-align: right; color: var(--lineno); } +/* generated content isn't part of a copied selection */ +#blob a.line::before { + content: attr(data-n); +} + #blob a.line:hover { color: var(--link); text-decoration: none;