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:
parent
8fc49f6b0a
commit
71d9263664
@ -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;
|
||||
|
@ -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)
|
||||
);
|
||||
|
@ -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')]); }
|
||||
)
|
||||
;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user