From 77c01f6caa7cd6709d8323e760896f16b37a3fd5 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Sun, 16 Mar 2025 11:42:14 +0100 Subject: Allow fragments in man: URLs When linking to an specific section of a manual by using the # fragment, we need to remove it before passing it to man(1), otherwise it will be interpreted as part of the manual page name. --- man.filter.dpi | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'man.filter.dpi') diff --git a/man.filter.dpi b/man.filter.dpi index 5b9adbc..afe880e 100755 --- a/man.filter.dpi +++ b/man.filter.dpi @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (c) 2023 Rodrigo Arias Mallo +# Copyright (c) 2023-2025 Rodrigo Arias Mallo # SPDX-License-Identifier: GPL-3.0-or-later IFS= read -d '>' auth # Ignore auth @@ -53,15 +53,17 @@ fix_br() { serve_manpage() { url="$1" ref="${url#"man:"}" + # Remove # fragment if any + cleanref=$(echo "$ref" | sed 's/#.*$//') # Reverse open(3) -> 3 open if given - manpage=$(echo "$ref" | sed 's/\(.*\)(\(.*\))/\2 \1/') + manpage=$(echo "$cleanref" | sed 's/\(.*\)(\(.*\))/\2 \1/') # If page not found, return 404 if [ -z "$manpage" ]; then serve_404 exit 0 fi if ! man -w $manpage 2>/dev/null; then - apropos=$(echo "$ref" | sed 's/(.*)//') + apropos=$(echo "$cleanref" | sed 's/(.*)//') serve_404 "$manpage" "$apropos" else printf "\n" -- cgit v1.2.3