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
Changes from 4 commits
d6d5f53
4d3600f
50952b3
a81aede
543a6c4
3aef89b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -987,7 +987,7 @@ protected function paragraph($Line) | |
# ~ | ||
# | ||
|
||
public function line($text) | ||
public function line($text, $non_nestables=array()) | ||
{ | ||
$markup = ''; | ||
|
||
|
@@ -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 (in_array($inlineType, $non_nestables)) | ||
{ | ||
continue; | ||
} | ||
|
||
$Inline = $this->{'inline'.$inlineType}($Excerpt); | ||
|
||
if ( ! isset($Inline)) | ||
|
@@ -1024,6 +1031,13 @@ public function line($text) | |
$Inline['position'] = $markerPosition; | ||
} | ||
|
||
# cause the new element to 'inherit' our non nestables | ||
|
||
foreach ($non_nestables as $non_nestable) | ||
{ | ||
$Inline['element']['non_nestables'][] = $non_nestable; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @PhrozenByte I did consider that, though there is no guarantee that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, didn't think about that. I agree that adding another check doesn't improve readability, so it's probably best to keep it the way you did 😃 |
||
} | ||
|
||
# the text that comes before the inline | ||
$unmarkedText = substr($text, 0, $Inline['position']); | ||
|
||
|
@@ -1183,6 +1197,7 @@ protected function inlineLink($Excerpt) | |
$Element = array( | ||
'name' => 'a', | ||
'handler' => 'line', | ||
'non_nestables' => array('Url', 'Link'), | ||
'text' => null, | ||
'attributes' => array( | ||
'href' => null, | ||
|
@@ -1410,9 +1425,14 @@ protected function element(array $Element) | |
{ | ||
$markup .= '>'; | ||
|
||
if (!isset($Element['non_nestables'])) | ||
{ | ||
$Element['non_nestables'] = array(); | ||
} | ||
|
||
if (isset($Element['handler'])) | ||
{ | ||
$markup .= $this->{$Element['handler']}($Element['text']); | ||
$markup .= $this->{$Element['handler']}($Element['text'], $Element['non_nestables']); | ||
} | ||
else | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about
if (!empty($non_nestables) && in_array($inlineType, $non_nestables))
?in_array()
really is very expensive, even with empty arrays.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds sensible, I'll commit that change when I get a sec :)