From 179a0c039f3817ff5b312c03b7919238a2e6ed9b Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Thu, 29 Oct 2026 14:37:26 -1000 Subject: Render the man pages that generators write DocBook, pod2man and hand written pages leaked roff onto the page: font escapes inside no fill blocks, comments, layout escapes such as \% and \c, the colours and half line moves around DocBook's links, and the requests and macro definitions their preambles open with. Those now draw nothing, the common named characters and strings render, .EX and pod2man's .Vb read as code, a .TP tag takes a line of its own and the alternating font macros switch fonts between their arguments. Anything rarer still falls back to its text. --- tests/extensions/test-about-render.lua | 71 +++++++++++++++++++++++++++++++++- tests/t0501-about-render.sh | 43 +++++++++++++++++++- 2 files changed, 110 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/extensions/test-about-render.lua b/tests/extensions/test-about-render.lua index 0571796..88c136c 100644 --- a/tests/extensions/test-about-render.lua +++ b/tests/extensions/test-about-render.lua @@ -257,6 +257,15 @@ 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 < 10) +-- The long forms of the man escapes scan for a closing bracket or quote, so +-- they are bounded the same way, and a line of openers stays linear. +started = os.clock() +render("page.1", string.rep("\\[", 100000)) +render("page.1", string.rep("\\f[", 100000)) +render("page.1", string.rep("\\h'", 100000)) +render("page.1", string.rep("\\s[", 100000)) +h.check("a line of unclosed man escapes renders quickly", os.clock() - started < 10) + out = render("README.md", "Title\n=====\n\nBody") h.contains("equals signs under a line make a heading", out, "

Title

Body

") @@ -334,13 +343,71 @@ h.contains("the bold macro renders strong", out, "

bold words out = render("page.1", "a \\fBbold\\fR c") h.contains("font escapes carry across a run", out, "

a bold c

") -out = render("page.1", "x \\(em y \\- z") -h.contains("character escapes are translated", out, "

x - y - z

") +out = render("page.1", "x \\(em y \\- z \\(bu \\[co]") +h.contains("character escapes are translated", out, "

x — y - z • ©

") + +out = render("page.1", "\\*(lqquoted\\*(rq\\*R") +h.contains("predefined strings are expanded", out, "

“quoted”®

") + +out = render("page.1", "a\\%b c\\:d \\s-1SMALL\\s0 text \\\" a comment") +h.contains("escapes that only steer the layout draw nothing", out, "

ab cd SMALL text

") out = render("page.1", ".nf\ncode \n.fi\nafter") h.contains("a no fill block renders as code", out, "
code <x>\n
") h.contains("filling resumes after it", out, "

after

") +out = render("page.1", ".nf\n\\fBgit\\fR \\-\\-version\n.fi") +h.contains("a no fill block shows the text of its escapes", out, "
git --version\n
") + +out = render("page.1", ".EX\nline \n.EE") +h.contains("an example block renders as code", out, "
line <one>\n
") + +out = render("page.1", ".TP\n.B \\-v\nBe verbose.") +h.contains("a tag takes a line of its own", out, "

-v
\nBe verbose.

") + +out = render("page.1", ".IP \\(bu 2\nAn item.\n.IP \\-v 4\nA flag.") +h.contains("a bullet leads its item", out, "

• \nAn item.

") +h.contains("a longer tag takes a line of its own", out, "

-v
\nA flag.

") + +out = render("page.1", ".BR ls (1),\n.IR file .txt") +h.contains("alternating macros switch fonts between arguments", out, + "ls(1),\nfile.txt") + +out = render("page.1", '.B "two words" three') +h.contains("a quoted argument keeps its blank", out, "two words three") + +out = render("page.1", "one\n.br\ntwo\n.\nthree") +h.contains("a break request breaks the line", out, "

one
\ntwo\nthree

") + +-- pod2man and asciidoctor open their pages with macro definitions and +-- conditional requests, none of which may reach the page as text. +out = render("page.1", table.concat({ + ".de Vb", ".nf", "..", ".de IX", "..", ".if n .ds Aq '", ".ie \\n(.g \\{\\", + ". nr x 1", ".\\}", ".SH NAME", ".IX Header \"NAME\"", ".Vb 2", "\\& code", ".Ve", "after", +}, "\n")) +h.excludes("a page's own macro is not drawn", out, "Header") +h.excludes("a roff request is not drawn", out, "Aq") +h.contains("the heading after the preamble renders", out, "

NAME

") +h.contains("pod2man's verbatim macros render code", out, "
  code\n
") +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

") + +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, + "

The Manual[1] here

") + +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

") + +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") +h.contains("DocBook's apostrophe string expands", out, "Don't") + + out = render("page.1", '.\\" a comment\nvisible') h.excludes("a roff comment is dropped", out, "comment") h.contains("the line after it renders", out, "visible") diff --git a/tests/t0501-about-render.sh b/tests/t0501-about-render.sh index 263c79b..339c5e2 100755 --- a/tests/t0501-about-render.sh +++ b/tests/t0501-about-render.sh @@ -39,7 +39,20 @@ test_expect_success 'create a repository with a markdown readme' ' See the [roadmap](ROADMAP.md#plan). EOF - git add README.md && + cat >tool.1 <<-\EOF && + .TH TOOL 1 + .SH NAME + tool \- does one thing \(em well + .SH OPTIONS + .TP + .B \-v + Be \fIverbose\fR. + .nf + tool \-v + .fi + EOF + echo "Plain notes & more" >NOTES && + git add README.md tool.1 NOTES && git commit -m "add readme" && git branch next ) @@ -53,11 +66,20 @@ test_expect_success 'point cgit at it through the about filter' ' repo.path=$PWD/repos/md/.git repo.readme=:README.md repo.about-filter=lua:$EXTENSIONS_DIRECTORY/about-render.lua + repo.url=man + repo.path=$PWD/repos/md/.git + repo.readme=:tool.1 + repo.about-filter=lua:$EXTENSIONS_DIRECTORY/about-render.lua + repo.url=txt + repo.path=$PWD/repos/md/.git + repo.readme=:NOTES + repo.about-filter=lua:$EXTENSIONS_DIRECTORY/about-render.lua EOF ' if test "$CGIT_HAS_LUA" -eq 1 then + test_set_prereq CGIT_LUA if cgit_lua_probe "$PWD/repos/md/.git" lpeg then test_set_prereq CGIT_LUA_LPEG @@ -91,10 +113,27 @@ test_expect_success CGIT_LUA_LPEG 'the link stays on the branch shown' ' grep "roadmap" tmp ' +test_expect_success CGIT_LUA_LPEG 'the about page renders a man page' ' + cgit_url "man/about/" >tmp && + grep "

NAME

" tmp && + grep "tool - does one thing — well" tmp && + grep "-v
" tmp && + grep "
tool -v <file>" tmp &&
+	! grep "\\\\f" tmp
+'
+
+test_expect_success CGIT_LUA 'the about page shows plain text as it is' '
+	cgit_url "txt/about/" >tmp &&
+	grep "
Plain <b>notes</b> & more" tmp
+'
+
 test_expect_success CGIT_LUA_NOLPEG 'without lpeg the readme is served escaped' '
 	cgit_url "md/about/" >tmp &&
 	grep "
" tmp &&
-	grep "# The Title" tmp
+	grep "# The Title" tmp &&
+	cgit_url "man/about/" >tmp &&
+	grep "
" tmp &&
+	grep ".SH NAME" tmp
 '
 
 test_done
-- 
cgit