Skip to content

Commit

Permalink
Merge pull request #433 from aidantwoods/patch-3
Browse files Browse the repository at this point in the history
Fix Issue #358 – preventing double nested links
  • Loading branch information
aidantwoods committed Feb 28, 2018
2 parents 48a053f + 3aef89b commit c192001
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions Parsedown.php
Expand Up @@ -1037,7 +1037,7 @@ protected function paragraph($Line)
# ~
#

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

Expand All @@ -1053,6 +1053,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 @@ -1074,6 +1081,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 @@ -1232,6 +1246,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 @@ -1464,9 +1479,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

0 comments on commit c192001

Please sign in to comment.