Browse Source

Markdown.pl: auto-open "<p>" when required

Given input like this:

    hi<p>_</p>there

avoid leaving a dangling text blob outside of any "p" section
like this:

    <p>hi</p><p>_</p>there

Instead, auto-open a new "p" section so the final text blob
ends up properly wrapped like so:

    <p>hi</p><p>_</p><p>there</p>

This reflects the actual rendering behavior of the client
"user agent" (aka browser) which would end up supplying the
missing <p>...</p> wrapper in any case.

By doing this the output better reflects the way the markup
actually renders.

The heuristic used to auto-open the "p" section may not always
auto-open a "p" when it should, but it should never auto-open
a "p" when it shouldn't.

Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
master
Kyle J. McKay 4 years ago
parent
commit
5711c23576
  1. 10
      Markdown.pl

10
Markdown.pl

@ -2793,9 +2793,17 @@ sub _SanitizeTags {
}
} if $validate;
while (pos($text) < $end) {
if ($text =~ /\G(\s+)/gc) {
$ans .= $1;
next;
}
if ($text =~ /\G([^<]+)/gc) {
if ($validate && @stack && $stack[$#stack]->[0] eq "\20") {
push(@stack,["p",pos($text)-length($1)]);
$ans .= "<p>";
}
$ans .= $1;
$lastmt = "" if $1 =~ /\S/;
$lastmt = "";
next;
}
my $tstart = pos($text);

Loading…
Cancel
Save