Experiment with mdoc formatting for torreas man page

Potentially more projects to follow.
This commit is contained in:
Yorhel 2023-11-19 15:13:29 +01:00
parent 4c6e5346e7
commit b9f55ade45
3 changed files with 24 additions and 5 deletions

View file

@ -70,7 +70,7 @@ PAGES=\
"yxml/man.md https://g.blicky.net/yxml.git/plain/yxml.md"\
"torreas.md"\
"torreas/changes.log https://g.blicky.net/torreas.git/plain/ChangeLog Torreas Release History"\
"torreas/man.pod https://g.blicky.net/torreas.git/plain/torreas.pod Torreas Manual"
"torreas/man.mdoc https://g.blicky.net/torreas.git/plain/torreas.1 Torreas Manual"
# Files generated by mkfeed.pl
@ -97,8 +97,11 @@ POD_MD := $(shell for i in ${PAGES}; do echo "$$i" | grep -Eo '^[^ ]+\.pod'
# List of .md files generated from .log files
CHANGES_MD := $(shell for i in ${PAGES}; do echo "$$i" | grep -Eo '^[^ ]+\.log' | sed -E 's/(.+)\.log$$/dat\/\1.md/'; done)
# List of .md files generated from .mdoc files
MDOC_MD := $(shell for i in ${PAGES}; do echo "$$i" | grep -Eo '^[^ ]+\.mdoc' | sed -E 's/(.+)\.mdoc$$/dat\/\1.md/'; done)
# All fetched & generated files
CLEAN := ${FETCH} ${POD_MD} ${CHANGES_MD} ${HTML_OUT} ${FEEDS}
CLEAN := ${FETCH} ${POD_MD} ${CHANGES_MD} ${MDOC_MD} ${HTML_OUT} ${FEEDS}
.PHONY: all clean
@ -136,13 +139,26 @@ ${CHANGES_MD}: dat/%.md: dat/%.log mkchangelog.pl
@./mkchangelog.pl "$*" "${shell for i in ${PAGES}; do case "$$i" in "$*.log "*) echo "$$i" | sed -E 's/[^ ]+ +[^ ]+ +//';; esac; done}" <"$<" >"$@"
# TODO: Add --strip-comments to pandoc when I have a version that supports it.
# pandoc doesn't support mdoc directly. Going through a `mandoc -T man` tends
# to generate nicer formatting, but runs into another issue:
# https://github.com/jgm/pandoc/issues/9201
# We'll have to settle for the quote-abusing `mandoc -T markdown` with some
# post-processing and fixups.
${MDOC_MD}: dat/%.md: dat/%.mdoc
@echo "MDOC $*"
@(echo "% ${shell for i in ${PAGES}; do case "$$i" in "$*.mdoc "*) echo "$$i" | sed -E 's/[^ ]+ +[^ ]+ +//';; esac; done}";\
mandoc -T markdown "$<" | \
tail -n +2 | head -n -2 | \
sed -E -e 's/-&#45;/\\--/g' -e 's/&#45;/-/g' -e 's/(^|[ ,.])([a-zA-Z0-9-]+)\(([1-8])\)/\1[\2(\3)](https:\/\/manned.org\/man\/\2.\3)/g' \
) >"$@"
${HTML_OUT}: pub/%.html: dat/%.md template.html
@echo "HTML $*"
@mkdir -p $$(dirname "$@")
@cat "$<" |\
./dllink.pl |\
pandoc -f markdown -t html5 --template template.html \
pandoc -f markdown -t html5 --strip-comments --template template.html \
--metadata path1=$$(echo "$*" | sed 's/\/.*//') \
--metadata path2=$$(echo "$*" | sed 's/\//-/' | sed 's/\/.*//') \
--metadata path3=$$(echo "$*" | sed 's/\//-/g') \