Add post-processor for HTML renders

Adds links to argument descriptions in synopsis
Adds links to man pages in the set (not to external ones)
Removes artifact from the way long opts are encoded
Makes description blurb inline, consistently with terminal output
This commit is contained in:
ISSOtm
2020-03-19 00:07:25 +01:00
parent 187f88aa50
commit 51e225cd75
2 changed files with 77 additions and 9 deletions

View File

@@ -197,15 +197,15 @@ checkpatch:
MANDOC := -Thtml -Ios=General -Oman=%N.%S.html -Ostyle=mandoc.css
wwwman:
$Qmandoc ${MANDOC} src/rgbds.7 > docs/rgbds.7.html
$Qmandoc ${MANDOC} src/gbz80.7 > docs/gbz80.7.html
$Qmandoc ${MANDOC} src/rgbds.5 > docs/rgbds.5.html
$Qmandoc ${MANDOC} src/asm/rgbasm.1 > docs/rgbasm.1.html
$Qmandoc ${MANDOC} src/asm/rgbasm.5 > docs/rgbasm.5.html
$Qmandoc ${MANDOC} src/fix/rgbfix.1 > docs/rgbfix.1.html
$Qmandoc ${MANDOC} src/link/rgblink.1 > docs/rgblink.1.html
$Qmandoc ${MANDOC} src/link/rgblink.5 > docs/rgblink.5.html
$Qmandoc ${MANDOC} src/gfx/rgbgfx.1 > docs/rgbgfx.1.html
$Qmandoc ${MANDOC} src/rgbds.7 | src/doc_postproc.awk > docs/rgbds.7.html
$Qmandoc ${MANDOC} src/gbz80.7 | src/doc_postproc.awk > docs/gbz80.7.html
$Qmandoc ${MANDOC} src/rgbds.5 | src/doc_postproc.awk > docs/rgbds.5.html
$Qmandoc ${MANDOC} src/asm/rgbasm.1 | src/doc_postproc.awk > docs/rgbasm.1.html
$Qmandoc ${MANDOC} src/asm/rgbasm.5 | src/doc_postproc.awk > docs/rgbasm.5.html
$Qmandoc ${MANDOC} src/fix/rgbfix.1 | src/doc_postproc.awk > docs/rgbfix.1.html
$Qmandoc ${MANDOC} src/link/rgblink.1 | src/doc_postproc.awk > docs/rgblink.1.html
$Qmandoc ${MANDOC} src/link/rgblink.5 | src/doc_postproc.awk > docs/rgblink.5.html
$Qmandoc ${MANDOC} src/gfx/rgbgfx.1 | src/doc_postproc.awk > docs/rgbgfx.1.html
# This target is used during development in order to prevent adding new issues
# to the source code. All warnings are treated as errors in order to block the

68
src/doc_postproc.awk Executable file
View File

@@ -0,0 +1,68 @@
#!/usr/bin/awk -f
BEGIN {
in_synopsis = 0
}
/<table class="Nm">/ {
in_synopsis = 1
}
/<\/table>/ {
# Resets synopsis state even when already reset, but whatever
in_synopsis = 0
}
/<code class="Fl">-[a-zA-Z]/ {
# Add links to arg descr in synopsis section
if (in_synopsis) {
while (match($0, /<code class="Fl">-[a-zA-Z]+/)) {
# 123456789012345678 -> 18 chars
optchars = substr($0, RSTART + 18, RLENGTH - 18)
i = length(optchars)
while (i) {
end = RSTART + 18 + i
i -= 1
len = i ? 1 : 2
$0 = sprintf("%s<a href=\"#%s\">%s</a>%s",
substr($0, 0, end - len - 1),
substr($0, end - 1, 1),
substr($0, end - len, len),
substr($0, end))
}
}
}
}
/<div class="Nd">/ {
# Make the description blurb inline, as with terminal output
gsub(/div/, "span")
}
BEGIN {
pages["gbz80", 7] = 1
pages["rgbds", 5] = 1
pages["rgbds", 7] = 1
pages["rgbasm", 1] = 1
pages["rgbasm", 5] = 1
pages["rgblink",1] = 1
pages["rgblink",5] = 1
pages["rgbfix", 1] = 1
pages["rgbgfx", 1] = 1
}
/<a class="Xr">/ {
# Link to other pages in the doc
for (i in pages) {
split(i, page, SUBSEP)
name = page[1]
section = page[2]
gsub(sprintf("<a class=\"Xr\">%s\\(%d\\)", name, section),
sprintf("<a class=\"Xr\" href=\"%s.%d.html\">%s(%d)", name, section, name, section))
}
}
{
# Make long opts (defined using `Fl Fl`) into a single tag
gsub(/<code class="Fl">-<\/code><code class="Fl">/, "<code class=\"Fl\">-")
}
{
print
}