diff --git a/src/Components/AcquisitioningBlock.php b/src/Components/AcquisitioningBlock.php new file mode 100644 index 0000000..6df3c9a --- /dev/null +++ b/src/Components/AcquisitioningBlock.php @@ -0,0 +1,13 @@ +acquired; - } -} diff --git a/src/Components/Blocks/BlockQuote.php b/src/Components/Blocks/BlockQuote.php index 5f2e09a..f14a0b9 100644 --- a/src/Components/Blocks/BlockQuote.php +++ b/src/Components/Blocks/BlockQuote.php @@ -16,8 +16,6 @@ use Erusev\Parsedown\State; final class BlockQuote implements ContinuableBlock { - use BlockAcquisition; - /** @var Lines */ private $Lines; diff --git a/src/Components/Blocks/FencedCode.php b/src/Components/Blocks/FencedCode.php index dab873c..c95d8d9 100644 --- a/src/Components/Blocks/FencedCode.php +++ b/src/Components/Blocks/FencedCode.php @@ -12,8 +12,6 @@ use Erusev\Parsedown\State; final class FencedCode implements ContinuableBlock { - use BlockAcquisition; - /** @var string */ private $code; diff --git a/src/Components/Blocks/Header.php b/src/Components/Blocks/Header.php index 3dfbb58..157ccba 100644 --- a/src/Components/Blocks/Header.php +++ b/src/Components/Blocks/Header.php @@ -13,8 +13,6 @@ use Erusev\Parsedown\State; final class Header implements Block { - use BlockAcquisition; - /** @var string */ private $text; diff --git a/src/Components/Blocks/IndentedCode.php b/src/Components/Blocks/IndentedCode.php index 22850a9..52a727b 100644 --- a/src/Components/Blocks/IndentedCode.php +++ b/src/Components/Blocks/IndentedCode.php @@ -13,8 +13,6 @@ use Erusev\Parsedown\State; final class IndentedCode implements ContinuableBlock { - use BlockAcquisition; - /** @var string */ private $code; diff --git a/src/Components/Blocks/Markup.php b/src/Components/Blocks/Markup.php index 512036c..363f9ab 100644 --- a/src/Components/Blocks/Markup.php +++ b/src/Components/Blocks/Markup.php @@ -15,8 +15,6 @@ use Erusev\Parsedown\State; final class Markup implements ContinuableBlock { - use BlockAcquisition; - const REGEX_HTML_ATTRIBUTE = '[a-zA-Z_:][\w:.-]*+(?:\s*+=\s*+(?:[^"\'=<>`\s]+|"[^"]*+"|\'[^\']*+\'))?+'; /** @var array{2: string, 3: string, 4: string, 5: string} */ diff --git a/src/Components/Blocks/Paragraph.php b/src/Components/Blocks/Paragraph.php index 7d4b7d4..81efec2 100644 --- a/src/Components/Blocks/Paragraph.php +++ b/src/Components/Blocks/Paragraph.php @@ -13,8 +13,6 @@ use Erusev\Parsedown\State; final class Paragraph implements ContinuableBlock { - use BlockAcquisition; - /** @var string */ private $text; diff --git a/src/Components/Blocks/Reference.php b/src/Components/Blocks/Reference.php index 4ba0987..a953aed 100644 --- a/src/Components/Blocks/Reference.php +++ b/src/Components/Blocks/Reference.php @@ -12,8 +12,6 @@ use Erusev\Parsedown\State; final class Reference implements StateUpdatingBlock { - use BlockAcquisition; - /** @var State */ private $State; diff --git a/src/Components/Blocks/Rule.php b/src/Components/Blocks/Rule.php index 893406d..41bc2e9 100644 --- a/src/Components/Blocks/Rule.php +++ b/src/Components/Blocks/Rule.php @@ -10,8 +10,6 @@ use Erusev\Parsedown\State; final class Rule implements Block { - use BlockAcquisition; - /** * @param Context $Context * @param Block|null $Block diff --git a/src/Components/Blocks/SetextHeader.php b/src/Components/Blocks/SetextHeader.php index b684dec..0df2bc5 100644 --- a/src/Components/Blocks/SetextHeader.php +++ b/src/Components/Blocks/SetextHeader.php @@ -4,16 +4,15 @@ namespace Erusev\Parsedown\Components\Blocks; use Erusev\Parsedown\AST\Handler; use Erusev\Parsedown\AST\StateRenderable; +use Erusev\Parsedown\Components\AcquisitioningBlock; use Erusev\Parsedown\Components\Block; use Erusev\Parsedown\Html\Renderables\Element; use Erusev\Parsedown\Parsedown; use Erusev\Parsedown\Parsing\Context; use Erusev\Parsedown\State; -final class SetextHeader implements Block +final class SetextHeader implements AcquisitioningBlock { - use BlockAcquisition; - /** @var string */ private $text; @@ -28,7 +27,6 @@ final class SetextHeader implements Block { $this->text = $text; $this->level = $level; - $this->acquired = true; } /** @@ -64,6 +62,12 @@ final class SetextHeader implements Block return null; } + /** @return bool */ + public function acquiredPrevious() + { + return true; + } + /** * @return Handler */ diff --git a/src/Components/Blocks/TList.php b/src/Components/Blocks/TList.php index 94405f4..e5f004a 100644 --- a/src/Components/Blocks/TList.php +++ b/src/Components/Blocks/TList.php @@ -15,8 +15,6 @@ use Erusev\Parsedown\State; final class TList implements ContinuableBlock { - use BlockAcquisition; - /** @var Lines[] */ private $Lis; diff --git a/src/Components/Blocks/Table.php b/src/Components/Blocks/Table.php index 25ab542..8c69661 100644 --- a/src/Components/Blocks/Table.php +++ b/src/Components/Blocks/Table.php @@ -4,6 +4,7 @@ namespace Erusev\Parsedown\Components\Blocks; use Erusev\Parsedown\AST\Handler; use Erusev\Parsedown\AST\StateRenderable; +use Erusev\Parsedown\Components\AcquisitioningBlock; use Erusev\Parsedown\Components\Block; use Erusev\Parsedown\Components\ContinuableBlock; use Erusev\Parsedown\Html\Renderables\Element; @@ -14,9 +15,10 @@ use Erusev\Parsedown\State; /** * @psalm-type _Alignment='left'|'center'|'right' */ -final class Table implements ContinuableBlock +final class Table implements AcquisitioningBlock, ContinuableBlock { - use BlockAcquisition; + /** @var bool */ + private $acquired; /** @var array */ private $alignments; @@ -165,6 +167,12 @@ final class Table implements ContinuableBlock return $alignments; } + /** @return bool */ + public function acquiredPrevious() + { + return true; + } + /** * @return Handler */ diff --git a/src/Parsedown.php b/src/Parsedown.php index 2958fe6..990543f 100644 --- a/src/Parsedown.php +++ b/src/Parsedown.php @@ -3,6 +3,7 @@ namespace Erusev\Parsedown; use Erusev\Parsedown\AST\StateRenderable; +use Erusev\Parsedown\Components\AcquisitioningBlock; use Erusev\Parsedown\Components\Block; use Erusev\Parsedown\Components\Blocks\Paragraph; use Erusev\Parsedown\Components\ContinuableBlock; @@ -113,7 +114,12 @@ final class Parsedown $State = $Block->latestState(); } - if (isset($CurrentBlock) && ! $Block->acquiredPrevious()) { + if (isset($CurrentBlock) + && ( + ! $Block instanceof AcquisitioningBlock + || ! $Block->acquiredPrevious() + ) + ) { $Blocks[] = $CurrentBlock; }