Skip to content

Commit 653e6cf

Browse files
committed
docs: cross-link manpage references from the narrative manuals
Extend the man_xref postprocessor to the User/HAL/Integrator HTML manuals, which cite man pages in the same name(section) form. A per-page manxref-linkbase attribute carries the depth-adjusted path to the language's man/man<N>/ tree; manpages keep the sibling default. Index-gated as before, so only real pages link and prose like TRUE(1) stays plain.
1 parent 27fe6b0 commit 653e6cf

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

docs/src/Submakefile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,14 @@ $(DOC_OUT_ADOC)/%.html: LCNC_CSSREL=$(shell python3 -c "print('../' * '$*'.count
12051205
# of the output depth. Add the +1 here, matching the $(DOC_SRCDIR) rule above.
12061206
$(DOC_OUT_ADOC)/en/%.html: LCNC_CSSREL=$(shell python3 -c "print('../' * (1 + '$*'.count('/')))")
12071207

1208+
# man_xref linkbase: relative path from this html page to its language's
1209+
# man/man<N>/ dirs. CSSREL points one level above the lang root (at the html
1210+
# root, where the css lives); the man tree sits inside the lang root, so this
1211+
# is CSSREL with one fewer "../" plus "man/". Translated stems include the
1212+
# lang dir; the English stem omits it, hence the extra step, mirroring CSSREL.
1213+
$(DOC_OUT_ADOC)/%.html: MANXREF_LINKBASE=$(shell python3 -c "print('../' * ('$*'.count('/') - 1) + 'man/')")
1214+
$(DOC_OUT_ADOC)/en/%.html: MANXREF_LINKBASE=$(shell python3 -c "print('../' * '$*'.count('/') + 'man/')")
1215+
12081216
# asciidoctor HTML rule used for every language.
12091217
# $1 lang tag (en, de, ...)
12101218
# $2 source root: $(DOC_SRCDIR) for English (DOC_SRCS_EN paths have no
@@ -1216,13 +1224,16 @@ $(DOC_OUT_ADOC)/en/%.html: LCNC_CSSREL=$(shell python3 -c "print('../' * (1 + '$
12161224
define ASCIIDOCTOR_HTML_RULE
12171225
# Order-only dep on .adoc-images-stamp so translated images are staged before
12181226
# the resolver probes for them at render (it also falls back to docs/src).
1219-
$$(patsubst %.adoc,$2/%.html,$$(DOC_SRCS_$(call toUC,$1)_SMALL)): $2/%.html: $2/%.adoc $$(DOC_SRCDIR)/docinfo.html $$(DOC_SRCDIR)/docinfo-header.html | .adoc-images-stamp
1227+
$$(patsubst %.adoc,$2/%.html,$$(DOC_SRCS_$(call toUC,$1)_SMALL)): $2/%.html: $2/%.adoc $$(DOC_SRCDIR)/docinfo.html $$(DOC_SRCDIR)/docinfo-header.html | .adoc-images-stamp manpages
12201228
$$(ECHO) "Building '$1' adoc to html: " $$<
12211229
$$(Q)asciidoctor -r $$(realpath $$(DOC_SRCDIR))/extensions/xref_resolver.rb \
12221230
-r $$(realpath $$(DOC_SRCDIR))/extensions/image_resolver.rb \
12231231
-r $$(realpath $$(DOC_SRCDIR))/extensions/rouge_hal.rb \
12241232
-r $$(realpath $$(DOC_SRCDIR))/extensions/rouge_ngc.rb \
12251233
-r $$(realpath $$(DOC_SRCDIR))/extensions/rouge_ini.rb \
1234+
-r $$(realpath $$(DOC_SRCDIR))/extensions/man_xref.rb \
1235+
-a "manxref-root=$$(realpath $$(if $$(filter en,$1),$$(DOC_MAN),$$(DOC_MAN)/$1))" \
1236+
-a "manxref-linkbase=$$(MANXREF_LINKBASE)" \
12261237
-a compat-mode \
12271238
-a "doc-languages=$$(LANGUAGES)" \
12281239
-a "lcnc-lang=$1" \

docs/src/extensions/man_xref.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@
1313
# so code samples, tag attributes and existing links are left untouched.
1414
# * Case-insensitive match ("AXIS(1)" => axis.1); visible text kept verbatim.
1515
#
16+
# Used for both the HTML manpages (sibling links under man/) and the narrative
17+
# manuals (User/HAL/Integrator), which reference man pages in the same
18+
# name(section) form and now link across into ../man/man<N>/.
19+
#
1620
# manxref-root (passed from the Submakefile) points at the troff man tree
1721
# docs/build/man[/<lang>], whose man<N>/ dirs enumerate every page including
1822
# generated component pages and .so stubs. Absent => no-op, safe to always load.
23+
# manxref-linkbase is the relative path from the page to those man<N>/ dirs
24+
# (default "../" for a sibling manpage; narrative pages pass their own depth).
1925

2026
require 'asciidoctor'
2127
require 'asciidoctor/extensions'
@@ -93,6 +99,12 @@ def process(document, output)
9399
self_name = (document.attr('mantitle') || '').downcase
94100
self_vol = (document.attr('manvolnum') || '').to_s
95101

102+
# Relative path from this page to the man<N>/ dirs. Manpages sit beside
103+
# each other under man/, so the default reaches a sibling section dir;
104+
# narrative pages pass their own depth-adjusted base (../man/, ../../man/).
105+
base = document.attr('manxref-linkbase')
106+
base = '../' if base.nil? || base.empty?
107+
96108
self.class.each_editable_text(output) do |text|
97109
text.gsub(TOKEN) do
98110
whole = Regexp.last_match(0)
@@ -101,7 +113,7 @@ def process(document, output)
101113
# Never link a page to itself.
102114
next whole if name.downcase == self_name && sec == self_vol
103115
href = idx["#{name.downcase}\t#{sec}"]
104-
href ? %(<a class="man-xref" href="../#{href}">#{whole}</a>) : whole
116+
href ? %(<a class="man-xref" href="#{base}#{href}">#{whole}</a>) : whole
105117
end
106118
end
107119
end

0 commit comments

Comments
 (0)