aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorY. Wang <yw05@forksworld.de>2022-08-10 14:33:33 +0200
committerY. Wang <yw05@forksworld.de>2022-08-10 14:33:33 +0200
commit48b9922071c6e338a3ab6ebdea01fc57940cd7f8 (patch)
tree2605f59e93b3dd51ad92019c3d39f919ed742cf4
parent80f2f33bfb2b9bf8d38db86aa7b1a982fd7a548d (diff)
downloadadvtrains-48b9922071c6e338a3ab6ebdea01fc57940cd7f8.tar.gz
advtrains-48b9922071c6e338a3ab6ebdea01fc57940cd7f8.tar.bz2
advtrains-48b9922071c6e338a3ab6ebdea01fc57940cd7f8.zip
Add "SEE ALSO" section to manual pages where applicable
-rw-r--r--Makefile9
-rw-r--r--assets/manual/filter_man.lua73
-rw-r--r--assets/manual/filter_man_md2tex.lua31
-rw-r--r--assets/manual/man/man7advtrains/rwt.7advtrains.md9
-rw-r--r--assets/manual/man/man7advtrains/speed.7advtrains.md7
5 files changed, 92 insertions, 37 deletions
diff --git a/Makefile b/Makefile
index 7beb1fc..ba1a371 100644
--- a/Makefile
+++ b/Makefile
@@ -9,6 +9,7 @@ MAN_PATH = $(MANUAL_ROOT)/man
MAN_SRCS = $(wildcard $(MAN_PATH)/*/*.md)
MAN_DSTS = $(MAN_SRCS:%.md=%)
MAN_TEXS = $(MAN_SRCS:%.md=%.tex)
+MAN_FILTER = $(MANUAL_ROOT)/filter_man.lua
TEX_PATH = $(MANUAL_ROOT)/tex
MAN_TEX = $(TEX_PATH)/man.tex
@@ -26,11 +27,11 @@ doc-pdf: $(TEX_MAIN_DSTS)
doc-man: $(MAN_DSTS)
find assets/manual/man -regex '.*/[^.]+\.[^.]+$$' | tar -cJf ${MANUAL_ROOT}/man.tar.xz -T -
-%:: %.md
- $(PANDOC) -s -t man -o $@ $<
+%:: %.md ${MAN_FILTER}
+ $(PANDOC) -L ${MAN_FILTER} -s -t man -o $@ $<
$(MAN_TEX): $(MAN_TEXS)
find $(MAN_PATH) -name '*.tex' -printf '\\input{../man/%P}\n' | sort > $(MAN_TEX)
-%.tex:: %.md ${MANUAL_ROOT}/filter_man_md2tex.lua
- $(PANDOC) -L ${MANUAL_ROOT}/filter_man_md2tex.lua -t latex -o $@ $<
+%.tex:: %.md ${MAN_FILTER}
+ $(PANDOC) -L ${MAN_FILTER} -t latex -o $@ $<
diff --git a/assets/manual/filter_man.lua b/assets/manual/filter_man.lua
new file mode 100644
index 0000000..0178462
--- /dev/null
+++ b/assets/manual/filter_man.lua
@@ -0,0 +1,73 @@
+local filters = {}
+
+local function add_filter(x)
+ table.insert(filters, x)
+end
+
+local is_latex = FORMAT:match "latex"
+local is_man = FORMAT:match "man"
+
+add_filter {
+ Pandoc = function(elem)
+ local seealso = elem.meta.seealso
+ if not seealso then
+ return
+ end
+ local blocks = elem.blocks
+ 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
+ end
+ blocks:insert(pandoc.Str(table.concat(seealso, ", ")))
+ else
+ local list = {}
+ for _, i in ipairs(seealso) do
+ local page = i[1].text
+ local pgname, pgsection = string.match(page, "^([^%)]+)%(([^%)]+)%)$")
+ local item = pandoc.Str(page)
+ if is_latex and pgname and pgsection then
+ pgname = pgname:gsub("_","\\string_")
+ item = pandoc.RawInline("latex", string.format("\\manref{%s}{%s}", pgname, pgsection))
+ end
+ table.insert(list, item)
+ end
+ blocks:insert(pandoc.BulletList(list))
+ end
+ return elem
+ end
+}
+
+if is_latex then
+ add_filter {
+ Str = function(elem)
+ if elem.tex == "Advtrains" then
+ return pandoc.RawInline("latex", "\\advtrains{}")
+ end
+ end
+ }
+ add_filter {
+ Header = function(elem)
+ local attr = {
+ class = "unnumbered unlisted",
+ }
+ return pandoc.Header(elem.level+1, elem.content, attr)
+ end,
+ }
+ 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,
+ }
+end
+
+return filters
diff --git a/assets/manual/filter_man_md2tex.lua b/assets/manual/filter_man_md2tex.lua
deleted file mode 100644
index fb21405..0000000
--- a/assets/manual/filter_man_md2tex.lua
+++ /dev/null
@@ -1,31 +0,0 @@
-return {
- {
- Str = function(elem)
- if elem.text == "Advtrains" then
- return pandoc.RawInline("latex", "\\advtrains{}")
- end
- end
- },
- {
- Header = function(elem)
- local attr = {
- class = "unnumbered unlisted",
- }
- return pandoc.Header(elem.level+1, elem.content, attr)
- end,
- },
- {
- 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,
- },
-}
diff --git a/assets/manual/man/man7advtrains/rwt.7advtrains.md b/assets/manual/man/man7advtrains/rwt.7advtrains.md
index 5e04d5e..5e15406 100644
--- a/assets/manual/man/man7advtrains/rwt.7advtrains.md
+++ b/assets/manual/man/man7advtrains/rwt.7advtrains.md
@@ -1,4 +1,11 @@
-% RWT(7ADVTRAINS) | Advtrains Developer's Manual
+---
+title: 'RWT(7ADVTRAINS) | Advtrains Developer''s Manual'
+seealso:
+- rwt_add(3advtrains)
+- rwt_copy(3advtrains)
+- rwt_last_rpt(3advtrains)
+- rwt_now(3advtrains)
+---
# NAME
`rwt` - Advtrains railway time
diff --git a/assets/manual/man/man7advtrains/speed.7advtrains.md b/assets/manual/man/man7advtrains/speed.7advtrains.md
index bf8ed08..0977546 100644
--- a/assets/manual/man/man7advtrains/speed.7advtrains.md
+++ b/assets/manual/man/man7advtrains/speed.7advtrains.md
@@ -1,4 +1,9 @@
-% SPEED(7ADVTRAINS) | Advtrains Developer's Manual
+---
+title: 'SPEED(7ADVTRAINS) | Advtrains Developer''s Manual'
+seealso:
+- speed_lessp(3advtrains)
+- speed_set_restriction(3advtrains)
+---
# NAME
`speed` - Advtrains speed limit library