diff --git a/Markdown.pl b/Markdown.pl index 324282e..eec3bec 100755 --- a/Markdown.pl +++ b/Markdown.pl @@ -3315,9 +3315,16 @@ sub _ProcessURLTag { } +my $oops_entities; +BEGIN { $oops_entities = qr/(?:lt|gt|amp|quot|apos|nbsp)/io; } + + sub _HTMLEncode { my $text = shift; + # Treat these accidents as though they had the needed ';' + $text =~ s/&($oops_entities)(?![A-Za-z0-9=;])/&$1;/go; + # Ampersand-encoding based entirely on Nat Irons's Amputator MT plugin: # http://bumppo.net/projects/amputator/ $text =~ s/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/&/g; @@ -3335,6 +3342,9 @@ sub _HTMLEncode { sub _EncodeAmps { my $text = shift; + # Treat these accidents as though they had the needed ';' + $text =~ s/&($oops_entities)(?![A-Za-z0-9=;])/&$1;/go; + # Ampersand-encoding based entirely on Nat Irons's Amputator MT plugin: # http://bumppo.net/projects/amputator/ $text =~ s/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/&/g; @@ -3348,6 +3358,9 @@ sub _EncodeAmpsAndAngles { my $text = shift; + # Treat these accidents as though they had the needed ';' + $text =~ s/&($oops_entities)(?![A-Za-z0-9=;])/&$1;/go; + # Ampersand-encoding based entirely on Nat Irons's Amputator MT plugin: # http://bumppo.net/projects/amputator/ $text =~ s/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/&/g;