]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
scripts/managen: fix parsing of markdown code sections
authorJay Satiro <raysatiro@yahoo.com>
Sun, 16 Feb 2025 07:49:43 +0000 (02:49 -0500)
committerJay Satiro <raysatiro@yahoo.com>
Sun, 16 Feb 2025 23:52:17 +0000 (18:52 -0500)
- Terminate a code section before parsing a heading line.

Prior to this change when a code line (eg "    code") was followed
by a heading line (eg "## heading") the code section in the output
was terminated after converting the header instead of before. That led
to some weird formatting outputs depending on the nroff or roffit etc.

With this change:

.nf
curl \--expand\-url https.//example.com/{{url:trim}}
.fi
.IP json

Without this change:

.nf
curl \--expand\-url https.//example.com/{{url:trim}}
.IP json
.fi

Closes https://github.com/curl/curl/pull/16345

scripts/managen

index 170d1f8bd3f6de29cf057ab55a5d496de4f32855..6621b1684c0203148a8d47a0167b8f6a7ffdce99 100755 (executable)
@@ -302,7 +302,30 @@ sub render {
             # skip leading blank lines
             next;
         }
+
         $start = 1;
+
+        if(/^[ \t]*\n/) {
+            # count and ignore blank lines
+            $blankline++;
+            next;
+        }
+        elsif($d =~ /^    (.*)/) {
+            my $word = $1;
+            if(!$quote && $manpage) {
+                push @desc, "\n" if($blankline);
+                push @desc, ".nf\n";
+                $blankline = 0;
+            }
+            $quote = 1;
+            $d = "$word\n";
+        }
+        elsif($quote) {
+            # end of quote
+            push @desc, ".fi\n" if($manpage);
+            $quote = 0;
+        }
+
         if(/^# (.*)/) {
             $header = 1;
             if($top != 1) {
@@ -366,26 +389,6 @@ sub render {
             print STDERR "$f:$line:1:ERROR: $cmd detected, use ##-style\n";
             return 3;
         }
-        elsif(/^[ \t]*\n/) {
-            # count and ignore blank lines
-            $blankline++;
-            next;
-        }
-        elsif($d =~ /^    (.*)/) {
-            my $word = $1;
-            if(!$quote && $manpage) {
-                push @desc, "\n" if($blankline);
-                push @desc, ".nf\n";
-                $blankline = 0;
-            }
-            $quote = 1;
-            $d = "$word\n";
-        }
-        elsif($quote && ($d !~ /^    (.*)/)) {
-            # end of quote
-            push @desc, ".fi\n" if($manpage);
-            $quote = 0;
-        }
 
         $d =~ s/`%DATE`/$date/g;
         $d =~ s/`%VERSION`/$version/g;