Skip to content

Commit c0af14b

Browse files
committed
docs: Convert manpages from DocBook to mdoc(7)
Writing those manpages directly in the target markup language allows to use its full expressiveness, unlike the generated output from DocBook. To create their HTML versions, we use mandoc(1), plus a small awk script to adapt the generated HTML to our needs. I tried groff(1) and man2html(1) but the former transforms nearly everything to simple <p> and the later tries to reproduce the rendering of a manpage in a terminal. Manpages in section 1 are moved to section 8 because they are commands to manage a system service, not general purpose commands. This commits requires a change in the website to integrate the new generated HTML manpages. [#143563295]
1 parent 775a415 commit c0af14b

18 files changed

+2337
-3437
lines changed

.gitignore

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,8 @@
1919
/escript
2020
rabbit.d
2121

22-
# Generated sources files.
23-
src/rabbit_ctl_usage.erl
24-
src/rabbit_plugins_usage.erl
25-
2622
# Generated documentation.
27-
docs/rabbitmq-echopid.man.xml
28-
docs/rabbitmq-env.conf.5
29-
docs/rabbitmq-env.conf.5.man.xml
30-
docs/rabbitmq-plugins.1
31-
docs/rabbitmq-plugins.1.man.xml
32-
docs/rabbitmq-server.1
33-
docs/rabbitmq-server.1.man.xml
34-
docs/rabbitmq-service.man.xml
35-
docs/rabbitmqctl.1
36-
docs/rabbitmqctl.1.man.xml
37-
docs/*.tmp
23+
docs/*.html
3824

3925
# Dialyzer
4026
*.plt

Makefile

Lines changed: 27 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,8 @@ $(subst __,_,$(patsubst $(DOCS_DIR)/rabbitmq%.1.xml, src/rabbit_%_usage.erl, $(s
133133
endef
134134

135135
DOCS_DIR = docs
136-
MANPAGES = $(patsubst %.xml, %, $(wildcard $(DOCS_DIR)/*.[0-9].xml))
137-
WEB_MANPAGES = $(patsubst %.xml, %.man.xml, $(wildcard $(DOCS_DIR)/*.[0-9].xml) $(DOCS_DIR)/rabbitmq-service.xml $(DOCS_DIR)/rabbitmq-echopid.xml)
138-
USAGES_XML = $(DOCS_DIR)/rabbitmqctl.1.xml $(DOCS_DIR)/rabbitmq-plugins.1.xml
139-
USAGES_ERL = $(foreach XML, $(USAGES_XML), $(call usage_xml_to_erl, $(XML)))
140-
141-
EXTRA_SOURCES += $(USAGES_ERL)
142-
143-
.DEFAULT_GOAL = all
144-
$(PROJECT).d:: $(EXTRA_SOURCES)
136+
MANPAGES = $(wildcard $(DOCS_DIR)/*.[0-9])
137+
WEB_MANPAGES = $(patsubst %,%.html,$(MANPAGES))
145138

146139
DEP_PLUGINS = rabbit_common/mk/rabbitmq-build.mk \
147140
rabbit_common/mk/rabbitmq-dist.mk \
@@ -205,10 +198,7 @@ copy-escripts:
205198
PREFIX="$(abspath $(CLI_ESCRIPTS_DIR))" \
206199
DESTDIR=
207200

208-
clean:: clean-extra-sources clean-escripts
209-
210-
clean-extra-sources:
211-
$(gen_verbose) rm -f $(EXTRA_SOURCES)
201+
clean:: clean-escripts
212202

213203
clean-escripts:
214204
$(gen_verbose) rm -rf "$(CLI_ESCRIPTS_DIR)"
@@ -217,45 +207,6 @@ clean-escripts:
217207
# Documentation.
218208
# --------------------------------------------------------------------
219209

220-
# xmlto can not read from standard input, so we mess with a tmp file.
221-
%: %.xml $(DOCS_DIR)/examples-to-end.xsl
222-
$(gen_verbose) xmlto --version | \
223-
grep -E '^xmlto version 0\.0\.([0-9]|1[1-8])$$' >/dev/null || \
224-
opt='--stringparam man.indent.verbatims=0' ; \
225-
xsltproc --novalid $(DOCS_DIR)/examples-to-end.xsl $< > $<.tmp && \
226-
xmlto -vv -o $(DOCS_DIR) $$opt man $< 2>&1 | (grep -v '^Note: Writing' || :) && \
227-
awk -F"'u " '/^\.HP / { print $$1; print $$2; next; } { print; }' "$@" > "$@.tmp" && \
228-
mv "$@.tmp" "$@" && \
229-
test -f $@ && \
230-
rm $<.tmp
231-
232-
# Use tmp files rather than a pipeline so that we get meaningful errors
233-
# Do not fold the cp into previous line, it's there to stop the file being
234-
# generated but empty if we fail
235-
define usage_dep
236-
$(call usage_xml_to_erl, $(1)):: $(1) $(DOCS_DIR)/usage.xsl
237-
$$(gen_verbose) xsltproc --novalid --stringparam modulename "`basename $$@ .erl`" \
238-
$(DOCS_DIR)/usage.xsl $$< > $$@.tmp && \
239-
sed -e 's/"/\\"/g' -e 's/%QUOTE%/"/g' $$@.tmp > $$@.tmp2 && \
240-
fold -s $$@.tmp2 > $$@.tmp3 && \
241-
mv $$@.tmp3 $$@ && \
242-
rm $$@.tmp $$@.tmp2
243-
endef
244-
245-
$(foreach XML,$(USAGES_XML),$(eval $(call usage_dep, $(XML))))
246-
247-
# We rename the file before xmlto sees it since xmlto will use the name of
248-
# the file to make internal links.
249-
%.man.xml: %.xml $(DOCS_DIR)/html-to-website-xml.xsl
250-
$(gen_verbose) cp $< `basename $< .xml`.xml && \
251-
xmlto xhtml-nochunks `basename $< .xml`.xml ; \
252-
rm `basename $< .xml`.xml && \
253-
cat `basename $< .xml`.html | \
254-
xsltproc --novalid $(DOCS_DIR)/remove-namespaces.xsl - | \
255-
xsltproc --novalid --stringparam original `basename $<` $(DOCS_DIR)/html-to-website-xml.xsl - | \
256-
xmllint --format - > $@ && \
257-
rm `basename $< .xml`.html
258-
259210
.PHONY: manpages web-manpages distclean-manpages
260211

261212
docs:: manpages web-manpages
@@ -266,9 +217,32 @@ manpages: $(MANPAGES)
266217
web-manpages: $(WEB_MANPAGES)
267218
@:
268219

220+
# We use mandoc(1) to convert manpages to HTML plus an awk script which
221+
# does:
222+
# 1. remove tables at the top and the bottom (they recall the
223+
# manpage name, section and date)
224+
# 2. "downgrade" headers by one level (eg. h1 -> h2)
225+
# 3. annotate .Dl lines with more CSS classes
226+
%.html: %
227+
$(gen_verbose) mandoc -T html -O 'fragment,man=%N.%S.html' "$<" | \
228+
awk '\
229+
/^<table class="head">$$/ { remove_table=1; next; } \
230+
/^<table class="foot">$$/ { remove_table=1; next; } \
231+
/^<\/table>$$/ { if (remove_table) { remove_table=0; next; } } \
232+
{ if (!remove_table) { \
233+
line=$$0; \
234+
gsub(/<h2/, "<h3", line); \
235+
gsub(/<\/h2>/, "</h3>", line); \
236+
gsub(/<h1/, "<h2", line); \
237+
gsub(/<\/h1>/, "</h2>", line); \
238+
gsub(/class="D1"/, "class=\"D1 sourcecode bash hljs\"", line); \
239+
print line; \
240+
} } \
241+
' > "$@"
242+
269243
distclean:: distclean-manpages
270244

271245
distclean-manpages::
272-
$(gen_verbose) rm -f $(MANPAGES) $(WEB_MANPAGES)
246+
$(gen_verbose) rm -f $(WEB_MANPAGES)
273247

274248
app-build: copy-escripts

docs/examples-to-end.xsl

Lines changed: 0 additions & 93 deletions
This file was deleted.

docs/html-to-website-xml.xsl

Lines changed: 0 additions & 90 deletions
This file was deleted.

0 commit comments

Comments
 (0)