summaryrefslogtreecommitdiff
path: root/man/manfilter.lua
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2022-04-27 10:01:09 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2022-04-27 10:02:37 -0700
commitc05f95773d21061f67494511652fe76a4f2708c1 (patch)
treec931184376b6a407213cd5a2cd2a9eeb19834cc5 /man/manfilter.lua
parent50c9848c34d220a2c834750c3d28f7c94e8b94a0 (diff)
Update manfilter for greater portability.
The tables in our man pages were not rendering correctly with mandoc, now used by default with macOS. mandoc doesn't allow man formatting inside table cells. For maximal portability, we now render the tables in plain format and include them as code blocks in the man page. Closes #8045.
Diffstat (limited to 'man/manfilter.lua')
-rw-r--r--man/manfilter.lua38
1 files changed, 18 insertions, 20 deletions
diff --git a/man/manfilter.lua b/man/manfilter.lua
index dd1a9ab56..6abd950fc 100644
--- a/man/manfilter.lua
+++ b/man/manfilter.lua
@@ -11,27 +11,25 @@ function Header(el)
end
end
--- unindent table content
+-- For portability with mandoc, which doesn't allow man commands
+-- inside table cells, we convert all tables to code blocks.
function Table(el)
- for _,body in ipairs(el.bodies) do
- handleTableBody(body)
- end
- return el
-end
-
-local function handleCell(el)
- if #el.contents > 0 and el.contents[1].t == "CodeBlock" then
- table.insert(el.contents, 1, pandoc.RawBlock("man", ".RS -14n"))
- table.insert(el.contents, pandoc.RawBlock("man", ".RE"))
- end
-end
-
-function handleTableBody(el)
- for _,row in ipairs(el.body) do
- for _,cell in ipairs(row.cells) do
- handleCell(cell)
- end
- end
+ local rendered = pandoc.write(pandoc.Pandoc({el}), "plain")
+ local adjusted = rendered -- tame grid table lines
+ :gsub("%+([=:][=:]+)",
+ function(s)
+ return " " .. string.rep("-", #s - 1)
+ end)
+ :gsub("(%+[-:][-:]+)",
+ function(s)
+ return ""
+ end)
+ :gsub("%+\n","\n")
+ :gsub("\n| ","\n|")
+ :gsub("|","")
+ return { pandoc.RawBlock("man", ".RS -14n"),
+ pandoc.CodeBlock(adjusted),
+ pandoc.RawBlock("man", ".RE") }
end