]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
doc: help2man: strip ANSI codes
authorPádraig Brady <P@draigBrady.com>
Mon, 29 Dec 2025 16:46:15 +0000 (16:46 +0000)
committerPádraig Brady <P@draigBrady.com>
Wed, 21 Jan 2026 13:51:39 +0000 (13:51 +0000)
* man/help2man: With these ANSI codes, output is corrupted,
so it's best to strip these, which allows --help to
outputting formatting and hyperlinks by default.

man/help2man

index 26f22cc1be9ab3918b10026e913d83280d66bfcb..a158c1c33522f1685f21efb1d31d8de24dba8346 100755 (executable)
@@ -793,6 +793,13 @@ sub get_option_value
        kark $err, $this_program, $opt, $prog, $extra;
     }
 
+    # Strip ANSI SGR formatting codes (colors, bold, etc.)
+    $value =~ s/\x1b\[[0-9;]*m//g;
+
+    # Strip OSC 8 hyperlinks (keep just the display text)
+    # TODO: Convert to roff \X escapes while preserving help2man's formatting
+    $value =~ s/\x1b\]8;;[^\x07]*\x07(.*?)\x1b\]8;;\x07/$1/gs;
+
     $value;
 }