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

Bug with inlineUrl method - not consider already wrapped anchor with the same URL #487

Closed
doiftrue opened this issue Mar 23, 2017 · 4 comments

Comments

@doiftrue
Copy link

Example text

foo <a href="http://seoso.ru/services.html">http://seoso.ru/services.html</a> bar

We have the same URL in href attribute and in link anchor. And what we get in output?

how fix it correctly?

@doiftrue
Copy link
Author

doiftrue commented Mar 23, 2017

For now I fix it so:

original method code - https://github.com/erusev/parsedown/blob/master/Parsedown.php#L1337

my fix

	protected function inlineUrl($Excerpt)
	{
		if ($this->urlsLinked !== true or ! isset($Excerpt['text'][2]) or $Excerpt['text'][2] !== '/')
		{
			return;
		}

		if (preg_match('/\bhttps?:[\/]{2}[^\s<]+\b\/*(.{4})/ui', $Excerpt['context'], $matches, PREG_OFFSET_CAPTURE))
		{
			if( $matches[1][0] == '</a>' ) return; // not process text like 'foo <a href="http://seoso.ru/services.html">http://seoso.ru/services.html</a> bar'

			$Inline = array(
				'extent' => strlen($matches[0][0]),
				'position' => $matches[0][1],
				'element' => array(
					'name' => 'a',
					'text' => $matches[0][0],
					'attributes' => array(
						'href' => $matches[0][0],
					),
				),
			);

			return $Inline;
		}
	}

add (.{4}) at the end of regular expression and then check if there is </a> after URL for not process inline URL if it is already in A tag...

@aidantwoods
Copy link
Collaborator

@erusev merging #433 would fix this issue 😃

@doiftrue
Copy link
Author

Not works :( I update parsedown code and what I need to add to inlineUrl() method?

@aidantwoods
Copy link
Collaborator

If you use this version of parsedown (https://github.com/aidantwoods/parsedown/blob/3aef89b3994d942d4eb85d6df0c8c43a157ac5d7/Parsedown.php)
Or apply the changes from the PR linked to it should prevent a tags being nested

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

2 participants