mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Merge pull request #594 from aidantwoods/enhancement/ast-recursion-helper
Add recursive helper for AST
This commit is contained in:
commit
1c8f6bc253
@ -1600,26 +1600,42 @@ 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_reduce(
|
||||
$Elements,
|
||||
function (array $Elements, array $Element) use ($closure) {
|
||||
$Elements[] = $this->elementApplyRecursive($closure, $Element);
|
||||
return $Elements;
|
||||
},
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
protected function element(array $Element)
|
||||
{
|
||||
if ($this->safeMode)
|
||||
|
Loading…
Reference in New Issue
Block a user