|
@@ -15,17 +15,18 @@ use League\CommonMark\Parser\Block\BlockStart;
|
|
|
use League\CommonMark\Parser\Block\BlockStartParserInterface;
|
|
|
use League\CommonMark\Parser\InlineParserEngineInterface;
|
|
|
use League\CommonMark\Parser\MarkdownParserStateInterface;
|
|
|
+use Twig\Node\TextNode;
|
|
|
|
|
|
class IntroParser extends AbstractBlockContinueParser implements BlockContinueParserWithInlinesInterface
|
|
|
{
|
|
|
protected IntroBlock $introBlock;
|
|
|
- protected Paragraph $paragraph;
|
|
|
+ // protected Paragraph $paragraph;
|
|
|
|
|
|
public function __construct(string $className ='')
|
|
|
{
|
|
|
$this->introBlock = new IntroBlock($className);
|
|
|
- $this->paragraph = new Paragraph();
|
|
|
- $this->introBlock->appendChild($this->paragraph);
|
|
|
+ // $this->paragraph = new Paragraph();
|
|
|
+ // $this->introBlock->appendChild($this->paragraph);
|
|
|
}
|
|
|
|
|
|
public function getBlock(): AbstractBlock
|
|
@@ -35,28 +36,50 @@ class IntroParser extends AbstractBlockContinueParser implements BlockContinuePa
|
|
|
|
|
|
public function tryContinue(Cursor $cursor, BlockContinueParserInterface $activeBlockParser): ?BlockContinue
|
|
|
{
|
|
|
- if ($cursor->getLine() === ':::') {
|
|
|
+ if (trim($cursor->getLine()) === ':::') {
|
|
|
return BlockContinue::finished();
|
|
|
}
|
|
|
- $line = $cursor->getRemainder();
|
|
|
- $this->paragraph->appendChild(new Text($line));
|
|
|
+ // $line = $cursor->getRemainder();
|
|
|
+ // $this->paragraph->appendChild(new Text($line));
|
|
|
+ //$this->introBlock->appendChild(new Text($cursor->getRemainder()));
|
|
|
|
|
|
+ $line = $cursor->getRemainder();
|
|
|
+ $paragraph =new Paragraph();
|
|
|
+ $paragraph->appendChild(new Text($line));
|
|
|
+ $this->introBlock->appendChild($paragraph);
|
|
|
return BlockContinue::at($cursor);
|
|
|
}
|
|
|
|
|
|
public function parseInlines(InlineParserEngineInterface $inlineParser): void
|
|
|
{
|
|
|
- $textContent = '';
|
|
|
- foreach($this->paragraph->children() as $child) {
|
|
|
- if ($child instanceof Text) {
|
|
|
- $textContent .= $child->getLiteral();
|
|
|
+ foreach($this->introBlock->children() as $child) {
|
|
|
+ if ($child instanceof Paragraph) {
|
|
|
+ $textContent = '';
|
|
|
+
|
|
|
+ foreach($child->children() as $textNode) {
|
|
|
+ if ($textNode instanceof Text) {
|
|
|
+ $textContent .= $textNode->getLiteral();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach($child->children() as $textNode) {
|
|
|
+ $textNode->detach();
|
|
|
+ }
|
|
|
+
|
|
|
+ $inlineParser->parse($textContent, $child);
|
|
|
}
|
|
|
}
|
|
|
- foreach($this->paragraph->children() as $child) {
|
|
|
- $child->detach();
|
|
|
- }
|
|
|
+ // $textContent = '';
|
|
|
+ // foreach($this->paragraph->children() as $child) {
|
|
|
+ // if ($child instanceof Text) {
|
|
|
+ // $textContent .= $child->getLiteral();
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // foreach($this->paragraph->children() as $child) {
|
|
|
+ // $child->detach();
|
|
|
+ // }
|
|
|
|
|
|
- $inlineParser->parse($textContent, $this->paragraph);
|
|
|
+ // $inlineParser->parse($textContent, $this->paragraph);
|
|
|
}
|
|
|
|
|
|
public static function createBlockStartParser(): BlockStartParserInterface
|