aboutsummaryrefslogtreecommitdiff
path: root/assets/manual/filter_man.lua
diff options
context:
space:
mode:
Diffstat (limited to 'assets/manual/filter_man.lua')
-rw-r--r--assets/manual/filter_man.lua56
1 files changed, 39 insertions, 17 deletions
diff --git a/assets/manual/filter_man.lua b/assets/manual/filter_man.lua
index bdb1b33..e80442b 100644
--- a/assets/manual/filter_man.lua
+++ b/assets/manual/filter_man.lua
@@ -1,3 +1,5 @@
+local text, utils = pandoc.text, pandoc.utils
+
local filters = {}
local function add_filter(x)
@@ -9,21 +11,36 @@ local is_man = FORMAT:match "man"
add_filter {
Pandoc = function(elem)
+ local blocks, meta = elem.blocks, elem.meta
+
+ local page_title = utils.stringify(meta.title)
+ local page_manual = utils.stringify(meta.manual)
+ local page_name, page_section = page_title:match("^([^%(]+)%(([^%)]+)%)$")
+
+ -- add page title
+ meta.title = pandoc.MetaString(string.format("%s | %s", text.upper(page_title), page_manual))
+ if is_latex then
+ local titleid = string.format("man:%s.%s", page_name, page_section)
+ local titleobj = pandoc.Header(1, pandoc.Code(page_title))
+ titleobj.identifier = titleid
+ blocks:insert(1, titleobj)
+ end
+
+ -- add "See Also" section
local seealso = elem.meta.seealso
if not seealso then
- return
+ return elem
end
- local blocks = elem.blocks
- blocks:insert(pandoc.Header(1, pandoc.Str("SEE ALSO")))
+ blocks:insert(pandoc.Header(1, pandoc.Str("See Also")))
if is_man then
for k, v in pairs(seealso) do
- seealso[k] = v[1].text
+ seealso[k] = utils.stringify(v)
end
blocks:insert(pandoc.Plain(table.concat(seealso, ", ")))
else
local list = {}
for _, i in ipairs(seealso) do
- local page = i[1].text
+ local page = utils.stringify(i)
local pgname, pgsection = string.match(page, "^([^%)]+)%(([^%)]+)%)$")
local item = pandoc.Plain(page)
if is_latex and pgname and pgsection then
@@ -48,25 +65,30 @@ if is_latex then
}
add_filter {
Header = function(elem)
+ if (elem.identifier or ""):match("^man:") then
+ return elem -- do not modify title header
+ end
local attr = {
class = "unnumbered unlisted",
}
return pandoc.Header(elem.level+1, elem.content, attr)
end,
}
+end
+
+if is_man then
add_filter {
- Pandoc = function(elem)
- local outputfn = PANDOC_STATE.output_file or error("No output file specified")
- local pgname, pgsection = outputfn:match("([^%./\\]+)%.([^%.]+)%.tex$")
- assert(pgname and pgsection, "Cannot fetch manpage name and section")
- local blocks = elem.blocks
- local titlestr = string.format("%s(%s)", pgname, pgsection)
- local titleid = string.format("man:%s.%s", pgname, pgsection)
- local titleobj = pandoc.Header(1, pandoc.Code(titlestr))
- titleobj.identifier = titleid
- blocks:insert(1, titleobj)
- return elem
- end,
+ Header = function(elem)
+ local filter = {
+ Str = function(elem)
+ return pandoc.Str(text.upper(elem.text))
+ end,
+ Code = function(elem)
+ return pandoc.Str(elem.text)
+ end,
+ }
+ return pandoc.walk_block(elem, filter)
+ end
}
end