Produce Blocks before converting to StateRenderables

(As we do with Inlines)
This commit is contained in:
Aidan Woods 2019-01-24 21:56:20 +00:00
parent 00821bd072
commit 14b3761687
No known key found for this signature in database
GPG Key ID: 9A6A8EFAA512BBB9

View File

@ -124,8 +124,20 @@ final class Parsedown
*/ */
public function lines(Lines $Lines) public function lines(Lines $Lines)
{ {
/** @var StateRenderable[] */ return \array_map(
$StateRenderables = []; /** @return StateRenderable */
function (Block $Block) { return $Block->stateRenderable($this); },
$this->blocks($Lines)
);
}
/**
* @return Block[]
*/
public function blocks(Lines $Lines)
{
/** @var Block[] */
$Blocks = [];
/** @var Block|null */ /** @var Block|null */
$Block = null; $Block = null;
/** @var Block|null */ /** @var Block|null */
@ -176,7 +188,7 @@ final class Parsedown
} }
if (isset($CurrentBlock) && ! $Block->acquiredPrevious()) { if (isset($CurrentBlock) && ! $Block->acquiredPrevious()) {
$StateRenderables[] = $CurrentBlock->stateRenderable($this); $Blocks[] = $CurrentBlock;
} }
$CurrentBlock = $Block; $CurrentBlock = $Block;
@ -195,7 +207,7 @@ final class Parsedown
$CurrentBlock = $Block; $CurrentBlock = $Block;
} else { } else {
if (isset($CurrentBlock)) { if (isset($CurrentBlock)) {
$StateRenderables[] = $CurrentBlock->stateRenderable($this); $Blocks[] = $CurrentBlock;
} }
$CurrentBlock = Paragraph::build($Context); $CurrentBlock = Paragraph::build($Context);
@ -205,12 +217,12 @@ final class Parsedown
# ~ # ~
if (isset($CurrentBlock)) { if (isset($CurrentBlock)) {
$StateRenderables[] = $CurrentBlock->stateRenderable($this); $Blocks[] = $CurrentBlock;
} }
# ~ # ~
return $StateRenderables; return $Blocks;
} }
# #