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

Fix Issue #358 – preventing double nested links #433

Merged
merged 6 commits into from Feb 28, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 22 additions & 2 deletions Parsedown.php
Expand Up @@ -987,7 +987,7 @@ protected function paragraph($Line)
# ~
#

public function line($text)
public function line($text, $nonNestables=array())
{
$markup = '';

Expand All @@ -1003,6 +1003,13 @@ public function line($text)

foreach ($this->InlineTypes[$marker] as $inlineType)
{
# check to see if the current inline type is nestable in the current context

if ( ! empty($nonNestables) and in_array($inlineType, $nonNestables))
{
continue;
}

$Inline = $this->{'inline'.$inlineType}($Excerpt);

if ( ! isset($Inline))
Expand All @@ -1024,6 +1031,13 @@ public function line($text)
$Inline['position'] = $markerPosition;
}

# cause the new element to 'inherit' our non nestables

foreach ($nonNestables as $non_nestable)
{
$Inline['element']['nonNestables'][] = $non_nestable;
}

# the text that comes before the inline
$unmarkedText = substr($text, 0, $Inline['position']);

Expand Down Expand Up @@ -1183,6 +1197,7 @@ protected function inlineLink($Excerpt)
$Element = array(
'name' => 'a',
'handler' => 'line',
'nonNestables' => array('Url', 'Link'),
'text' => null,
'attributes' => array(
'href' => null,
Expand Down Expand Up @@ -1410,9 +1425,14 @@ protected function element(array $Element)
{
$markup .= '>';

if (!isset($Element['nonNestables']))
{
$Element['nonNestables'] = array();
}

if (isset($Element['handler']))
{
$markup .= $this->{$Element['handler']}($Element['text']);
$markup .= $this->{$Element['handler']}($Element['text'], $Element['nonNestables']);
}
else
{
Expand Down