From 28d3c5dced240a541917b3d8a7bef2ee9cd6a48c Mon Sep 17 00:00:00 2001 From: Jay Satiro Date: Sun, 16 Feb 2025 02:49:43 -0500 Subject: [PATCH] scripts/managen: fix parsing of markdown code sections - 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 | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/scripts/managen b/scripts/managen index 170d1f8bd3..6621b1684c 100755 --- a/scripts/managen +++ b/scripts/managen @@ -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; -- 2.47.3