]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
doc: help2man: account for undisplayed markup in indenting calculations
authorPádraig Brady <P@draigBrady.com>
Fri, 16 Jan 2026 18:09:16 +0000 (18:09 +0000)
committerPádraig Brady <P@draigBrady.com>
Wed, 21 Jan 2026 13:51:39 +0000 (13:51 +0000)
* man/help2man: This is significant with the indented line
following the dd bs=BYTES "option" at least.

man/help2man

index d778ac215953edb953e45f95ab2ced0361f64d01..dd04caa57bcc3c58a2137d5b9d9cbe12564b8f4a 100755 (executable)
@@ -50,6 +50,7 @@ sub get_option_value;
 sub convert_option;
 sub fix_italic_spacing;
 sub set_indent;
+sub visual_length;
 
 my $version_info = enc_user sprintf _(<<'EOT'), $this_program, $this_version;
 GNU %s %s
@@ -537,12 +538,12 @@ while (length)
     if (s/^( {1,10}([+-]\S.*?))(?:(  +(?!-))|\n( {7,}))(\S.*)\n//)
     {
        $matched .= $& if %append_match;
-       $indent = set_indent length ($4 || "$1$3");
+       $indent = set_indent visual_length ($4 || "$1$3");
        $content = ".TP\n\x84$2\n\x84$5\n";
        unless ($4)
        {
            # Indent may be different on second line.
-           $indent = set_indent length $& if /^ {20,}/;
+           $indent = set_indent visual_length $& if /^ {20,}/;
        }
     }
 
@@ -558,7 +559,7 @@ while (length)
     elsif (s/^( +(\S.*?)  +)(\S.*)\n//)
     {
        $matched .= $& if %append_match;
-       $indent = set_indent length $1;
+       $indent = set_indent visual_length $1;
        $content = ".TP\n\x84$2\n\x84$3\n";
     }
 
@@ -566,7 +567,7 @@ while (length)
     elsif (s/^( +)(\S.*)\n//)
     {
        $matched .= $& if %append_match;
-       $indent = set_indent length $1;
+       $indent = set_indent visual_length $1;
        $content = ".IP\n\x84$2\n";
     }
 
@@ -869,3 +870,13 @@ sub set_indent
     $i .= ',' . ($_[0] + 4) if $loose_indent;
     return $i;
 }
+
+# Return visual length of a string, ignoring hyperlink markers.
+# Markers are \x01<digits>\x02 (opening) and \x03 (closing).
+sub visual_length
+{
+    local $_ = shift;
+    s/\x01\d+\x02//g;
+    s/\x03//g;
+    return length;
+}