public function processDocument(Document $document) { $walker = $document->walker(); while ($event = $walker->next()) { $node = $event->getNode(); if ($event->isEntering() || !$node instanceof Attributes) { continue; } list($target, $direction) = $this->findTargetAndDirection($node); if ($target) { if (($parent = $target->parent()) instanceof ListItem && $parent->parent() instanceof ListBlock && $parent->parent()->isTight()) { $target = $parent; } if ($direction === self::DIRECTION_SUFFIX) { $attributes = AttributesUtils::merge($target, $node->getAttributes()); } else { $attributes = AttributesUtils::merge($node->getAttributes(), $target); } $target->data['attributes'] = $attributes; } if ($node instanceof AbstractBlock && $node->endsWithBlankLine() && $node->next() && $node->previous()) { $node->previous()->setLastLineBlank(true); } $node->detach(); } }
/** * @param Document $document * * @return void */ public function processDocument(Document $document) { /** @var TableOfContents[] $tocs */ $tocs = []; $headings = []; $walker = $document->walker(); while ($event = $walker->next()) { $node = $event->getNode(); if ($node instanceof TableOfContents && !$event->isEntering()) { $tocs[] = $node; continue; } if (!$node instanceof Heading || !$event->isEntering()) { continue; } $id = $this->addId($node); $headings[] = new Entry($node, $id); } if (count($headings) && (count($tocs) || $this->hasAutoTOC())) { $generated = $this->generate($headings); if (count($tocs)) { foreach ($tocs as $toc) { $toc->appendChild($this->render($generated->getChildren())); } } else { $document->prependChild($this->render($generated->getChildren())); } } }
public function __construct(Document $document, Environment $environment) { $this->doc = $document; $this->tip = $this->doc; $this->container = $this->doc; $this->environment = $environment; $this->referenceParser = new ReferenceParser($document->getReferenceMap()); $this->blockCloser = new UnmatchedBlockCloser($this); }
public function testRender() { $class = $this->getRendererClass(); $renderer = new $class(); $doc = new Document(); $doc->appendChild(new Paragraph()); $color = new Color(); $color->setForceStyle(true); $cliRenderer = new CliRenderer([Paragraph::class => new ParagraphRenderer()], [], $color); $this->assertEquals("\n\n", $renderer->render($doc, $cliRenderer)); }
public function finalize(ContextInterface $context) { parent::finalize($context); $this->applyAttributes($this); $parent = $this->getParent(); $parent->removeChild($this); foreach ($this->getChildren() as $child) { $parent->addChild($child); } }
/** * Process the CommonMark AST * * @param Document $document CommonMark AST * @return void */ public function processDocument(Document $document) { $walker = $document->walker(); while ($event = $walker->next()) { $node = $event->getNode(); // Process link starts as refers-to relations if ($node instanceof Link && $event->isEntering()) { $this->addRefersToRelation($this->stripFragment($node->getUrl()), empty($node->data['title']) ? null : $node->data['title']); } // Process image starts as embeds relations if ($node instanceof Image && $event->isEntering()) { $this->addEmbedsRelation($this->stripFragment($node->getUrl()), empty($node->data['title']) ? null : $node->data['title']); } } }