Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

One too many conversions of html special characters & and < when inside em text #353

Open
Sameh-R-Labib opened this issue Apr 10, 2021 · 2 comments

Comments

@Sameh-R-Labib
Copy link

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

markdown
static
The code

@lorddoumer
Copy link

I experience the same issue, when enabeling Markdown Extra at Grav CMS with inline code - any idea how to solve this?

@michelf
Copy link
Owner

michelf commented Dec 21, 2021

This is related to the no_entities mode. I suppose using the hashing system to make the generated &amp; 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('&amp;', ':'), $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+);)/',
								'&amp;', $text);
		}
		// Encode remaining <'s
		$text = str_replace('<', $this->hashPart('&lt;', ':'), $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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants