pandoc/man/manfilter.lua
John MacFarlane c05f95773d 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.
2022-04-27 10:02:37 -07:00

44 lines
1.2 KiB
Lua

-- we use preloaded text to get a UTF-8 aware 'upper' function
local text = require('text')
-- capitalize level 1 headers
function Header(el)
if el.level == 1 then
return pandoc.walk_block(el, {
Str = function(el)
return pandoc.Str(text.upper(el.text))
end })
end
end
-- For portability with mandoc, which doesn't allow man commands
-- inside table cells, we convert all tables to code blocks.
function Table(el)
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
-- replace links with link text
function Link(el)
return el.content
end
-- remove notes
function Note(el)
return {}
end