Open Sameh-R-Labib opened 3 years ago
I experience the same issue, when enabeling Markdown Extra at Grav CMS with inline code - any idea how to solve this?
This is related to the no_entities mode. I suppose using the hashing system to make the generated &
invisible to subsequent passes would fix the issue. For instance by adding two hashPart
calls in the encodeAmpsAndAngles
function:
protected function encodeAmpsAndAngles($text) {
if ($this->no_entities) {
$text = str_replace('&', $this->hashPart('&', ':'), $text);
} else {
// 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 remaining <'s
$text = str_replace('<', $this->hashPart('<', ':'), $text);
return $text;
}
This is not a terribly efficient way of doing it (calling hashPart
every time encodeAmpsAndAngles
is called), but it should work.
It's a bit sad there's nothing in the test suite for the no_entities mode.
your code has a bug where if an ampersand or a less than sign is found in code marked (in markdown) as em via single asterisks the resulting html will contain double the encoding of the html special characters into their corresponding html entities. I've attached three screenshots: 1) markdown 2) resulting html 3) php code which calls your function