From bb04aa6c800bc179d74fecc2ac2b4e810758b15d Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 31 Oct 2026 13:12:15 -0700 Subject: Drop the readme hooks that nothing reads Nothing in assets/ or in README's list of hooks reads a fenced block's data-lang or the manpage class on a man page's wrapper, so the header now names the two wrappers the stylesheet does style. --- custom/extensions/about-render.lua | 21 +++++++-------------- tests/extensions/test-about-render.lua | 9 ++++----- tests/t0501-about-render.sh | 2 +- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/custom/extensions/about-render.lua b/custom/extensions/about-render.lua index 808dd08..9474225 100644 --- a/custom/extensions/about-render.lua +++ b/custom/extensions/about-render.lua @@ -3,8 +3,9 @@ -- interpreter so a readme costs no extra process per request. Markdown, man -- pages and plain text are the three formats, chosen from the readme's file -- extension, and anything that fails to parse falls back to escaped plain --- text. The wrappers it emits carry the classes that assets/cgit.css styles. --- It runs on Lua 5.1 through 5.5 and LuaJIT. +-- text. Markdown and man pages come out in div.markdown and plain text in +-- pre.plaintext, the two wrappers assets/cgit.css styles. It runs on Lua 5.1 +-- through 5.5 and LuaJIT. -- -- about-filter=lua:/usr/local/lib/cgit/filters/about-render.lua @@ -285,13 +286,7 @@ emit_blocks = function(blocks) elseif kind == "hr" then html("
") elseif kind == "code" then - html("
")
+			html("
")
 			html_txt(block.text)
 			html("
") elseif kind == "blockquote" then @@ -452,7 +447,6 @@ if has_lpeg then return nodes end - local lang_char = R("az", "AZ", "09") + S("_.+#-") local heading_line = C(P("#") * P("#") ^ -5) * space ^ 1 * C(P(1) ^ 0) -- A run of equals signs or dashes under a paragraph turns it into a -- heading, as on GitHub, rather than reading as more of its text. @@ -463,7 +457,7 @@ if has_lpeg then return space ^ 0 * P(mark) * (space ^ 0 * P(mark)) ^ 2 * space ^ 0 * eol end local break_line = thematic("-") + thematic("*") + thematic("_") - local fence_line = space ^ 0 * (C(P("`") ^ 3) + C(P("~") ^ 3)) * space ^ 0 * C(lang_char ^ 0) + local fence_line = space ^ 0 * (C(P("`") ^ 3) + C(P("~") ^ 3)) local close_backtick = space ^ 0 * P("`") ^ 3 * space ^ 0 * eol local close_tilde = space ^ 0 * P("~") ^ 3 * space ^ 0 * eol local quote_line = space ^ 0 * P(">") @@ -548,7 +542,7 @@ if has_lpeg then local blocks, i, n = {}, 1, #lines while i <= n do local line = lines[i] - local fence, lang = fence_line:match(line) + local fence = fence_line:match(line) local hashes, title = heading_line:match(line) local mark = item_line:match(line) if line:match("^%s*$") then @@ -568,7 +562,6 @@ if has_lpeg then end blocks[#blocks + 1] = { kind = "code", - lang = lang, text = body, } elseif hashes then @@ -1007,7 +1000,7 @@ if has_lpeg then if not ok then return render_plaintext(text) end - html("
") + html("
") pcall(emit_blocks, blocks) html("
") end diff --git a/tests/extensions/test-about-render.lua b/tests/extensions/test-about-render.lua index 88c136c..b744e95 100644 --- a/tests/extensions/test-about-render.lua +++ b/tests/extensions/test-about-render.lua @@ -219,8 +219,7 @@ out = render("README.md", "[![a](x.svg)](y)\n![b](z.svg)\n\ntext") h.contains("a paragraph of badges leaves nothing behind", out, "

text

") out = render("README.md", "```lua\nlocal x = 1 < 2\n```\nafter") -h.contains("a fenced block carries its language", out, - "
local x = 1 < 2\n
") +h.contains("a fenced block renders as code", out, "
local x = 1 < 2\n
") h.contains("text after the fence renders on", out, "

after

") out = render("README.md", "~~~\n**not bold**\n~~~") @@ -329,7 +328,7 @@ 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

") @@ -393,7 +392,7 @@ h.contains("text after the definitions renders", out, "

after

") out = render("page.1", ".if n \\\n\\{\\\n.ds x y\n.\\}\nafter") h.contains("a conditional block's requests and braces draw nothing", out, - "

after

") + "

after

") out = render("page.1", "The \\m[blue]\\fBManual\\fR\\m[]\\s-2\\u[1]\\d\\s+2 here") h.contains("DocBook's link colours and footnote marks draw nothing", out, @@ -401,7 +400,7 @@ h.contains("DocBook's link colours and footnote marks draw nothing", out, out = render("page.1", ".de x\n.B hidden\n.. \nshown") h.contains("a definition ends at two dots with blanks after them", out, - "

shown

") + "

shown

") out = render("page.1", ".TP\n.PD 0\n.B \\-a\nall\n.PD\nDon\\*(Aqt") h.excludes("a spacing macro draws nothing", out, ">0") diff --git a/tests/t0501-about-render.sh b/tests/t0501-about-render.sh index 339c5e2..222ddfd 100755 --- a/tests/t0501-about-render.sh +++ b/tests/t0501-about-render.sh @@ -115,7 +115,7 @@ test_expect_success CGIT_LUA_LPEG 'the link stays on the branch shown' ' test_expect_success CGIT_LUA_LPEG 'the about page renders a man page' ' cgit_url "man/about/" >tmp && - grep "

NAME

" tmp && + grep "

NAME

" tmp && grep "tool - does one thing — well" tmp && grep "-v
" tmp && grep "
tool -v <file>" tmp &&
-- 
cgit 2.11.1