1
0
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:
Aidan Woods 2018-04-01 16:55:10 +01:00
parent 68736f8800
commit 9026b1abdb
No known key found for this signature in database
GPG Key ID: 9A6A8EFAA512BBB9

View File

@ -1588,26 +1588,39 @@ class Parsedown
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']))
{
$Element['elements'] = $this->handleElementsRecursive($Element['elements']);
$Element['elements'] = $this->elementsApplyRecursive($closure, $Element['elements']);
}
elseif (isset($Element['element']))
{
$Element['element'] = $this->handleElementRecursive($Element['element']);
$Element['element'] = $this->elementApplyRecursive($closure, $Element['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)
{
if ($this->safeMode)