mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Line handler may prevent specified element nesting
This commit serves to add comments detailing parts of the new functionality, and to adjust syntax preferences to match that of the surrounding document. The commit title also now reflects the most significant change made.
This commit is contained in:
parent
4d3600f273
commit
50952b3243
@ -1003,24 +1003,21 @@ class Parsedown
|
|||||||
|
|
||||||
foreach ($this->InlineTypes[$marker] as $inlineType)
|
foreach ($this->InlineTypes[$marker] as $inlineType)
|
||||||
{
|
{
|
||||||
|
# check to see if the current inline type is nestable in the current context
|
||||||
|
|
||||||
foreach ($non_nestables as $key => $non_nestable)
|
foreach ($non_nestables as $key => $non_nestable)
|
||||||
{
|
{
|
||||||
if (is_array($non_nestable))
|
# case that we used array syntax
|
||||||
{
|
if (is_array($non_nestable) and $non_nestable[0] === $inlineType)
|
||||||
|
|
||||||
if ($non_nestable[0] === $inlineType)
|
|
||||||
{
|
{
|
||||||
continue 2;
|
continue 2;
|
||||||
}
|
}
|
||||||
}
|
# case that we used plain string syntax
|
||||||
else
|
elseif ( ! is_array($non_nestable) and $non_nestable === $inlineType)
|
||||||
{
|
|
||||||
if ($non_nestable === $inlineType)
|
|
||||||
{
|
{
|
||||||
continue 2;
|
continue 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$Inline = $this->{'inline'.$inlineType}($Excerpt);
|
$Inline = $this->{'inline'.$inlineType}($Excerpt);
|
||||||
|
|
||||||
@ -1043,26 +1040,28 @@ class Parsedown
|
|||||||
$Inline['position'] = $markerPosition;
|
$Inline['position'] = $markerPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# cause the new element to 'inherit' our non nestables, if appropriate
|
||||||
|
|
||||||
foreach ($non_nestables as $key => $non_nestable)
|
foreach ($non_nestables as $key => $non_nestable)
|
||||||
{
|
{
|
||||||
if (is_array($non_nestable) && isset($non_nestable[1]) && is_int($non_nestable[1])){
|
# array syntax, and depth is sufficient to pass on
|
||||||
if($non_nestable[1] > 1)
|
if (is_array($non_nestable) and isset($non_nestable[1]) and
|
||||||
|
is_int($non_nestable[1]) and $non_nestable[1] > 1)
|
||||||
{
|
{
|
||||||
$Inline['element']['non_nestables'][] = array($non_nestable[0], $non_nestable[1] -1);
|
$Inline['element']['non_nestables'][] = array($non_nestable[0], $non_nestable[1] -1);
|
||||||
}
|
}
|
||||||
|
# array syntax, and depth is indefinite
|
||||||
}
|
elseif (is_array($non_nestable) and ! isset($non_nestable[1]))
|
||||||
elseif (is_array($non_nestable) && ! isset($non_nestable[1]))
|
|
||||||
{
|
{
|
||||||
$Inline['element']['non_nestables'][] = array($non_nestable[0]);
|
$Inline['element']['non_nestables'][] = array($non_nestable[0]);
|
||||||
}
|
}
|
||||||
|
# string syntax, so depth is indefinite
|
||||||
elseif ( ! is_array($non_nestable))
|
elseif ( ! is_array($non_nestable))
|
||||||
{
|
{
|
||||||
$Inline['element']['non_nestables'][] = $non_nestable;
|
$Inline['element']['non_nestables'][] = $non_nestable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# the text that comes before the inline
|
# the text that comes before the inline
|
||||||
$unmarkedText = substr($text, 0, $Inline['position']);
|
$unmarkedText = substr($text, 0, $Inline['position']);
|
||||||
|
|
||||||
@ -1450,7 +1449,10 @@ class Parsedown
|
|||||||
{
|
{
|
||||||
$markup .= '>';
|
$markup .= '>';
|
||||||
|
|
||||||
if(!isset($Element['non_nestables'])) $Element['non_nestables'] = array();
|
if (!isset($Element['non_nestables']))
|
||||||
|
{
|
||||||
|
$Element['non_nestables'] = array();
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($Element['handler']))
|
if (isset($Element['handler']))
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user