diff --git a/markdown.php b/markdown.php index 789319b..c4aee64 100644 --- a/markdown.php +++ b/markdown.php @@ -1264,20 +1264,21 @@ class Markdown_Parser { function encodeAmpsAndAngles($text) { - # Smart processing for ampersands and angle brackets that need to be encoded. + # + # Smart processing for ampersands and angle brackets that need to + # be encoded. Valid character entities are left alone unless the + # no-entities mode is set. + # if ($this->no_entities) { $text = str_replace('&', '&', $text); - $text = str_replace('<', '<', $text); - return $text; + } else { + # Ampersand-encoding based entirely on Nat Irons's Amputator + # MT plugin: + $text = preg_replace('/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/', + '&', $text);; } - - # Ampersand-encoding based entirely on Nat Irons's Amputator MT plugin: - # http://bumppo.net/projects/amputator/ - $text = preg_replace('/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/', - '&', $text);; - - # Encode naked <'s - $text = preg_replace('{<(?![a-z/?\$!%])}i', '<', $text); + # Encode remaining <'s + $text = str_replace('<', '<', $text); return $text; }