mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Add recursive helper for AST, use this for implementation of calling handler
recursively
This commit is contained in:
parent
68736f8800
commit
9026b1abdb
@ -1588,26 +1588,39 @@ class Parsedown
|
|||||||
|
|
||||||
protected function handleElementRecursive(array $Element)
|
protected function handleElementRecursive(array $Element)
|
||||||
{
|
{
|
||||||
$Element = $this->handle($Element);
|
return $this->elementApplyRecursive(array($this, 'handle'), $Element);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function handleElementsRecursive(array $Elements)
|
||||||
|
{
|
||||||
|
return $this->elementsApplyRecursive(array($this, 'handle'), $Elements);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function elementApplyRecursive($closure, array $Element)
|
||||||
|
{
|
||||||
|
$Element = call_user_func($closure, $Element);
|
||||||
|
|
||||||
if (isset($Element['elements']))
|
if (isset($Element['elements']))
|
||||||
{
|
{
|
||||||
$Element['elements'] = $this->handleElementsRecursive($Element['elements']);
|
$Element['elements'] = $this->elementsApplyRecursive($closure, $Element['elements']);
|
||||||
}
|
}
|
||||||
elseif (isset($Element['element']))
|
elseif (isset($Element['element']))
|
||||||
{
|
{
|
||||||
$Element['element'] = $this->handleElementRecursive($Element['element']);
|
$Element['element'] = $this->elementApplyRecursive($closure, $Element['element']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $Element;
|
return $Element;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function handleElementsRecursive(array $Elements)
|
protected function elementsApplyRecursive($closure, array $Elements)
|
||||||
{
|
{
|
||||||
return array_map(array($this, 'handleElementRecursive'), $Elements);
|
return array_map(
|
||||||
|
array($this, 'elementApplyRecursive'),
|
||||||
|
array_fill(0, count($Elements), $closure),
|
||||||
|
$Elements
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected function element(array $Element)
|
protected function element(array $Element)
|
||||||
{
|
{
|
||||||
if ($this->safeMode)
|
if ($this->safeMode)
|
||||||
|
Loading…
Reference in New Issue
Block a user