Actually, the make rule is not general enough,
as it's not triggered with `make doc/coreutils.html` or `make web-manual`.

Therefore I'm replacing it with the attached, which wraps makeinfo,
and thus will post process the html in all cases.

cheers,
Padraig
From 88196ad915e9d18fa0702d998efcfb7461666e3d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]>
Date: Tue, 9 Dec 2025 17:07:13 +0000
Subject: [PATCH] doc: support html post processing in all cases

Previously the html-local make rule only worked for `make html`.
Instead add support for `make doc/coreutils.html` or `make web-manual`
through the use of a makeinfo wrapper.

* doc/local.mk: Move post processing from here to ...
* build-aux/makeinfo-wrapper.sh: ... here.
* cfg.mk: Ensure our wrapper is called with MAKEINFO.
Also pass --no-node-files so redirection html files
are not created for each anchor.
---
 build-aux/makeinfo-wrapper.sh | 36 +++++++++++++++++++++++++++++++++++
 cfg.mk                        |  5 +++++
 doc/local.mk                  |  8 --------
 3 files changed, 41 insertions(+), 8 deletions(-)
 create mode 100755 build-aux/makeinfo-wrapper.sh

diff --git a/build-aux/makeinfo-wrapper.sh b/build-aux/makeinfo-wrapper.sh
new file mode 100755
index 000000000..042068d77
--- /dev/null
+++ b/build-aux/makeinfo-wrapper.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+# Wrapper around makeinfo that post-processes HTML output to replace _002d with -
+# Only on lines containing "option", corresponding to our @optAnchor macro.
+# Note texi uses "-" in anchors for spaces, hence why it escapes - with _002d.
+
+makeinfo "$@" || exit
+
+sed_anchor_cleanup=\
+'/id=.*_002doption/{ s/id="\([^"]*\)_002doption/id="\1/g; s/_002d/-/g; }'
+
+case " $* " in
+  *" --html"*)
+    # Find the output file/directory
+    output=""
+    next_is_output=false
+    for arg in "$@"; do
+      if [ "$next_is_output" = true ]; then
+        output="$arg"
+        break
+      fi
+      case "$arg" in
+        -o) next_is_output=true ;;
+        --output=*) output="${arg#--output=}" ;;
+      esac
+    done
+
+    if [ -n "$output" ]; then
+      test -f "$output" && NAMES='*' || NAMES='*.html'
+      find "$output" -name "$NAMES" -type f |
+        while read htmlfile; do
+          sed -e "$sed_anchor_cleanup" "$htmlfile" > "$htmlfile.t" &&
+          mv "$htmlfile.t" "$htmlfile"
+        done
+    fi
+    ;;
+esac
diff --git a/cfg.mk b/cfg.mk
index df4926da5..e0d90cf83 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -17,6 +17,11 @@
 # Used in maint.mk's web-manual rule
 manual_title = Core GNU utilities
 
+# html post processing
+export MAKEINFO = $(abs_top_srcdir)/build-aux/makeinfo-wrapper.sh
+# Don't create node redirection files for each anchor
+gendocs_options_ = --common --no-node-files
+
 # Use the direct link.  This is guaranteed to work immediately, while
 # it can take a while for the faster mirror links to become usable.
 url_dir_list = https://ftp.gnu.org/gnu/$(PACKAGE)
diff --git a/doc/local.mk b/doc/local.mk
index 1287fca85..a1efbe82e 100644
--- a/doc/local.mk
+++ b/doc/local.mk
@@ -132,12 +132,4 @@ sc-lower-case-var:
 
 check-local: check-texinfo
 
-# Post-process generated HTML to clean up anchor IDs
-_sed_anchor_cleanup = \
-  -e '/id=.*_002doption/ { s/id="\([^"]*\)_002doption/id="\1/g; s/_002d/-/g; }'
-html-local: $(HTMLS)
-	$(AM_V_GEN)for htmlfile in $(HTMLS); do \
-	  sed $(_sed_anchor_cleanup) $$htmlfile > $$htmlfile-t \
-	    && mv $$htmlfile-t $$htmlfile; done
-
 .PHONY: html-local
-- 
2.51.1

Reply via email to