commit a9157374e77dc9abf01ebf6eeef29e88d590c616
parent 94aabf32924783829c9db7a602cd31423eca9a52
Author: Leah (ctucx) <leah@ctu.cx>
Date: Tue, 24 May 2022 12:36:51 +0200
parent 94aabf32924783829c9db7a602cd31423eca9a52
Author: Leah (ctucx) <leah@ctu.cx>
Date: Tue, 24 May 2022 12:36:51 +0200
writeblobhtml: refactor html output
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/stagit.c b/stagit.c @@ -618,11 +618,11 @@ 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> "; + const char *nfmt = "<a href=\"#L%zu\" id=\"L%zu\">%zu</a> "; const char *s = git_blob_rawcontent(blob); len = git_blob_rawsize(blob); - fputs("<pre id=\"blob\">\n", fp); + fputs("<pre id=\"blob\"><span class=\"line-number\">", fp); if (len > 0) { for (i = 0, prev = 0; i < len; i++) { @@ -630,7 +630,6 @@ writeblobhtml(FILE *fp, const git_blob *blob) continue; n++; fprintf(fp, nfmt, n, n, n); - xmlencodeline(fp, &s[prev], i - prev + 1); putc('\n', fp); prev = i + 1; } @@ -638,11 +637,25 @@ writeblobhtml(FILE *fp, const git_blob *blob) if ((len - prev) > 0) { n++; fprintf(fp, nfmt, n, n, n); + } + } + + fputs("</span><code>", fp); + + if (len > 0) { + for (i = 0, prev = 0; i < len; i++) { + if (s[i] != '\n') continue; + xmlencodeline(fp, &s[prev], i - prev + 1); + putc('\n', fp); + prev = i + 1; + } + /* trailing data */ + if ((len - prev) > 0) { xmlencodeline(fp, &s[prev], len - prev); } } - fputs("</pre>\n", fp); + fputs("</code></pre><div class=\"clearfix\"></div>", fp); return n; }