forked from jgm/pandoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanfilter.lua
44 lines (39 loc) · 1.24 KB
/
manfilter.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
-- 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