Browse Source

Markdown.pl: minor empty tag improvments

Even though block tags such as "<p/>" should not appear in
valid XHTML documents, the internal validator (which is
enabled by default) will properly expand "<p/>" to "<p></p>".

However, the block formatting code fails to notice such
an empty tag block leading to it being wrapped in a spurious
"<p>...</p>" pair before it's expanded by the validation code.

Attempt to recognize some of these valid-for-xml-but-not-xhtml
blocks earlier to produce better output.

This is not a perfect fix, but it's an improvement.

It's really an odd edge case anyway that's unlikely to be
encountered very often.

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

21
Markdown.pl

@ -936,6 +936,27 @@ sub _HashHTMLBlocks {
$g_html_blocks{$key} = $1;
"\n\n" . $key . "\n\n";
}eigmx;
#
# Now match any empty block tags that should have been paired
#
$text =~ s{
( # save in $1
^ # start of line (with /m)
(?:\Q$idt\E)? # optional lead in
<(?:$block_tags_b) # start tag = $2
\b # word break
(?:[^<>])*? #
/?> # the matching end tag
[ ]* # trailing spaces
(?=\n+|\Z) # followed by a newline or end of document
)
}{
my $key = block_id($1);
$g_html_blocks{$key} = $1;
"\n\n" . $key . "\n\n";
}eigmx;
# Special case just for <hr />. It was easier to make a special case than
# to make the other regex more complicated.
$text =~ s{

Loading…
Cancel
Save