From aee34c95d83cf66bcacd0848a5f4ab0a1ccc198f Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Fri, 16 Oct 2026 18:05:28 -1000 Subject: Give readme headings anchors like GitHub's A readme's links to its own sections, as in a table of contents, had nothing on the page to land on. --- tests/extensions/test-about-render.lua | 29 +++++++++++++++++++++-------- tests/t0501-about-render.sh | 2 +- 2 files changed, 22 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/extensions/test-about-render.lua b/tests/extensions/test-about-render.lua index 3925dfd..cb1c736 100644 --- a/tests/extensions/test-about-render.lua +++ b/tests/extensions/test-about-render.lua @@ -73,19 +73,31 @@ end -- Markdown. out = render("README.md", "# Title") -h.contains("a heading renders inside the wrapper", out, "

Title

") +h.contains("a heading renders inside the wrapper", out, "

Title

") out = render("README.md", "## Sub ##") -h.contains("trailing hashes are stripped from a heading", out, "

Sub

") +h.contains("trailing hashes are stripped from a heading", out, "

Sub

") out = render("README.md", "# C#") -h.contains("a hash ending a word stays in the heading", out, "

C#

") +h.contains("a hash ending a word stays in the heading", out, "

C#

") + +out = render("README.md", "## The `run` [Command](x), Again!") +h.contains("an anchor is the heading's text in lower case", out, "

") + +out = render("README.md", "# Twice\n# Twice\n# twice") +h.contains("a repeated anchor is counted", out, "

Twice

Twice

") + +out = render("README.md", "# About") +h.contains("no heading takes an id of the page", out, "

") + +out = render("README.md", "# ???") +h.contains("a heading of punctuation gets no anchor", out, "

???

") out = render("README.MD", "# Upper") -h.contains("the extension matches whatever its case", out, "

Upper

") +h.contains("the extension matches whatever its case", out, "

Upper

") out = render("readme.markdown", "# Long") -h.contains("the long markdown extension dispatches too", out, "

Long

") +h.contains("the long markdown extension dispatches too", out, "

Long

") out = render("README.md", "line one\nline two") h.contains("the lines of a paragraph run together", out, "

line one\nline two

") @@ -241,6 +253,7 @@ h.check("an emphasis bomb still renders something", #out > 0) -- request for minutes. Both lines below took seconds before. local started = os.clock() render("README.md", "# a" .. string.rep(" ", 3000) .. "b") +render("README.md", string.rep("# a\n", 50000)) render("README.md", "| a | b |\n|---|---|\n| x" .. string.rep(" ", 40000) .. "y | z |") h.check("a long run of spaces is trimmed quickly", os.clock() - started < 1) @@ -281,13 +294,13 @@ h.contains("an oversized readme renders as plain text", out, "

NAME

") +h.contains("a section heading renders", out, "

NAME

") out = render("page.man", '.SH "TWO WORDS"') -h.contains("a quoted heading argument is unquoted", out, "

TWO WORDS

") +h.contains("a quoted heading argument is unquoted", out, "

TWO WORDS

") out = render("page.3", ".SS Details") -h.contains("a subsection renders one level down", out, "

Details

") +h.contains("a subsection renders one level down", out, "

Details

") out = render("page.1", ".B bold words\nplain after") h.contains("the bold macro renders strong", out, "

bold words\nplain after

") diff --git a/tests/t0501-about-render.sh b/tests/t0501-about-render.sh index b47c11d..f339526 100755 --- a/tests/t0501-about-render.sh +++ b/tests/t0501-about-render.sh @@ -71,7 +71,7 @@ fi test_expect_success CGIT_LUA_LPEG 'the about page renders the markdown' ' cgit_url "md/about/" >tmp && - grep "

The Title

" tmp && + grep "

The Title

" tmp && grep "bold" tmp ' -- cgit