1
0
mirror of https://github.com/erusev/parsedown.git synced 2023-08-10 21:13:06 +03:00

Pass State to render stack closure

This commit is contained in:
Aidan Woods 2021-10-13 18:50:04 +01:00
parent 8fc49f6b0a
commit 71d9263664
No known key found for this signature in database
GPG Key ID: 9A6A8EFAA512BBB9
3 changed files with 13 additions and 10 deletions

View File

@ -4,14 +4,15 @@ namespace Erusev\Parsedown\Configurables;
use Erusev\Parsedown\Configurable;
use Erusev\Parsedown\Html\Renderable;
use Erusev\Parsedown\State;
final class RenderStack implements Configurable
{
/** @var list<\Closure(Renderable[]):Renderable[]> */
/** @var list<\Closure(Renderable[],State):Renderable[]> */
private $stack;
/**
* @param list<\Closure(Renderable[]):Renderable[]> $stack
* @param list<\Closure(Renderable[],State):Renderable[]> $stack
*/
private function __construct($stack = [])
{
@ -25,7 +26,7 @@ final class RenderStack implements Configurable
}
/**
* @param \Closure(Renderable[]):Renderable[] $RenderMap
* @param \Closure(Renderable[],State):Renderable[] $RenderMap
* @return self
*/
public function push(\Closure $RenderMap): self
@ -33,7 +34,7 @@ final class RenderStack implements Configurable
return new self(\array_merge($this->stack, [$RenderMap]));
}
/** @return list<\Closure(Renderable[]):Renderable[]> */
/** @return list<\Closure(Renderable[],State):Renderable[]> */
public function getStack(): array
{
return $this->stack;

View File

@ -49,11 +49,11 @@ final class Parsedown
\array_reverse($State->get(RenderStack::class)->getStack()),
/**
* @param Renderable[] $Renderables
* @param \Closure(Renderable[]):Renderable[] $RenderMap
* @param \Closure(Renderable[],State):Renderable[] $RenderMap
* @return Renderable[]
*/
function (array $Renderables, \Closure $RenderMap): array {
return $RenderMap($Renderables);
return $RenderMap($Renderables, $this->State);
},
$State->applyTo($StateRenderables)
);

View File

@ -23,16 +23,18 @@ final class RenderStackTest extends TestCase
->push(
/**
* @param Renderable[] $Rs
* return Renderable[]
* @param State $_
* @return Renderable[]
*/
function ($Rs) { return \array_merge($Rs, [new Text('baz')]); }
function ($Rs, $_) { return \array_merge($Rs, [new Text('baz')]); }
)
->push(
/**
* @param Renderable[] $Rs
* return Renderable[]
* @param State $_
* @return Renderable[]
*/
function ($Rs) { return \array_merge($Rs, [new Text('bar')]); }
function ($Rs, $_) { return \array_merge($Rs, [new Text('bar')]); }
)
;