1
0
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:
Aidan Woods 2018-04-02 19:53:58 +01:00 committed by GitHub
commit 1c8f6bc253
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)