From a04101db46e96176f0a751a2211f817b3b569c9d Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Wed, 30 Sep 2020 23:26:54 -0700 Subject: [PATCH] Markdown.pl: minor empty tag improvments Even though block tags such as "

" should not appear in valid XHTML documents, the internal validator (which is enabled by default) will properly expand "

" to "

". However, the block formatting code fails to notice such an empty tag block leading to it being wrapped in a spurious "

...

" 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 --- Markdown.pl | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Markdown.pl b/Markdown.pl index e1e0c6e..8864f93 100755 --- a/Markdown.pl +++ b/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
. It was easier to make a special case than # to make the other regex more complicated. $text =~ s{