diff --git a/Markdown.pl b/Markdown.pl index 0d9d22c..7ede5bd 100755 --- a/Markdown.pl +++ b/Markdown.pl @@ -1830,6 +1830,40 @@ sub _FormParagraphs { } +sub _EncodeHTML { + my $val = shift; + $val =~ s/&/&/g; + $val =~ s/}) { + return _EncodeHTML($tag); + } else { + return $tag; + } + } + if ($tag !~ m{^<$g_possible_tag_name[\s>]} && $tag !~ m{^<$g_possible_tag_name/>$}) { + return _EncodeHTML($tag); + } + return $tag; +} + + sub _EncodeAmpsAndAngles { # Smart processing for ampersands and angle brackets that need to be encoded. @@ -1841,6 +1875,10 @@ sub _EncodeAmpsAndAngles { # Encode naked <'s $text =~ s{<(?![a-z/?\$!])}{<}gi; + $text =~ s{<(?=[^>]*$)}{<}g; + + # Encode <'s that cannot possibly be a start or end tag + $text =~ s{(<[^>]*>)}{_DoTag($1)}ige; return $text; }