From e9d025d178dc24462f3ed4df29dad55e82ddf99d Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Sun, 11 Oct 2020 14:56:06 -0700 Subject: [PATCH] Markdown.pl: avoid superfluous leading

Since each "paragraph" is wrapped between a "

" and "

" this input:

hi

bye has been producing this output:

hi

bye

Correct this so that if the leading "

" of the paragraph wrapper is immediately auto-closed then it's simply discarded rather than creating a bogus "

" section. With this change the previous input now produces this output:

hi

bye

The bogus leading "

" sections have been omitted and the output looks much nicer. Signed-off-by: Kyle J. McKay --- Markdown.pl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Markdown.pl b/Markdown.pl index 8871693..725fe37 100755 --- a/Markdown.pl +++ b/Markdown.pl @@ -2779,7 +2779,12 @@ sub _SanitizeTags { elsif ($tagocl{$s}) {$c = $tagacl{$s}} else {return} while (@stack && $c->{$stack[$#stack]->[0]}) { - $ans .= "[0] . ">"; + if ($stack[$#stack]->[2] && + $stack[$#stack]->[1]+3 eq $_[1]) { + $ans .= ""; + } else { + $ans .= "[0] . ">"; + } if ($stack[$#stack]->[2]) { $stack[$#stack]->[0] = "\20"; } else { @@ -2820,7 +2825,7 @@ sub _SanitizeTags { $lastmt = $styp == -3 ? $tt : ""; $tt = "p" if $autocloseflag; if ($validate && $styp) { - &$autoclopen($tt) if $styp != 2; + &$autoclopen($tt, $tstart) if $styp != 2; if ($styp == 1) { push(@stack,[$tt,$tstart,$autocloseflag]); } elsif ($styp == 2) { @@ -2870,6 +2875,9 @@ sub _SanitizeTags { } _xmlfail(@errs) unless !@errs; } + # Remove any unwanted extra leading

sections + $ans =~ s{

}{}gs if $validate; + return $ans."\n"; }