summaryrefslogtreecommitdiff
path: root/cgithub/src/app.test.ts
diff options
context:
space:
mode:
authorJoe Mou <dev@mou.fo>2026-09-03 01:26:44 -0400
committerJoe Mou <dev@mou.fo>2026-09-03 01:27:35 -0400
commit501587e256a065816f7eb6007030e728955a32dc (patch)
treed218635dd8403ec7904a3248b0f7d8efee34b74f /cgithub/src/app.test.ts
parentf951c579f7093cc5c61bcb3c0905c7a6729df065 (diff)
Anchor blob lines so #L fragments work
Wrap each rendered line in a <span id="Ln">, for both syntax-highlighted and plain-text blobs, and shade the line a fragment targets.
Diffstat (limited to 'cgithub/src/app.test.ts')
-rw-r--r--cgithub/src/app.test.ts23
1 files changed, 23 insertions, 0 deletions
diff --git a/cgithub/src/app.test.ts b/cgithub/src/app.test.ts
index 3ecebd0..265465e 100644
--- a/cgithub/src/app.test.ts
+++ b/cgithub/src/app.test.ts
@@ -124,6 +124,29 @@ describe("blob view", () => {
assert.match(html, /This file cannot be displayed\./);
});
+ it("should give each syntax-highlighted line an anchor", () => {
+ const html = eta.render("blob.eta", {
+ ...blob,
+ path: "src/app.ts",
+ htmlLines: ['<span class="pl-k">const</span> x;', "x++;"],
+ });
+
+ assert.match(
+ html,
+ /<code><span id="L1"><span class="pl-k">const<\/span> x;<\/span>\n<span id="L2">x\+\+;<\/span><\/code>/,
+ );
+ });
+
+ it("should give each plain-text line an anchor", () => {
+ const html = eta.render("blob.eta", {
+ ...blob,
+ path: "notes.txt",
+ textLines: ["a < b", "c"],
+ });
+
+ assert.match(html, /<code><span id="L1">a &lt; b<\/span>\n<span id="L2">c<\/span><\/code>/);
+ });
+
it("should offer the raw file when there is nothing to display", () => {
const html = eta.render("blob.eta", blob);