public function parse(ContextInterface $context, Cursor $cursor) { $document = $context->getDocument(); $tip = $context->getTip(); if (!$document->getLastChild() instanceof AttributesDocument) { $attributesDocument = new AttributesDocument(); foreach ($document->getChildren() as $child) { $document->removeChild($child); $attributesDocument->addChild($child); } $document->addChild($attributesDocument); if ($tip instanceof Document) { $context->setTip($attributesDocument); } } $state = $cursor->saveState(); $attributes = AttributesUtils::parse($cursor); if (empty($attributes)) { return false; } if (null !== $cursor->getFirstNonSpaceCharacter()) { $cursor->restoreState($state); return false; } $prepend = $tip instanceof Document || !$tip->getParent() instanceof Document && $context->getBlockCloser()->areAllClosed(); $context->addBlock(new Attributes($attributes, $prepend ? Attributes::PREPEND : Attributes::APPEND)); $context->setBlocksParsed(true); return true; }
/** * @param ContextInterface $context * @param Cursor $cursor */ public function handleRemainingContents(ContextInterface $context, Cursor $cursor) { if ($cursor->isBlank()) { return; } $context->addBlock(new Paragraph()); $cursor->advanceToFirstNonSpace(); $context->getTip()->addLine($cursor->getRemainder()); }
/** * @param ContextInterface $context * @param Cursor $cursor * * @return bool */ public function parse(ContextInterface $context, Cursor $cursor) { if (!$cursor->isIndented()) { return false; } if ($context->getTip() instanceof Paragraph) { return false; } if ($cursor->isBlank()) { return false; } $cursor->advanceBy(Cursor::INDENT_LEVEL, true); $context->addBlock(new IndentedCode()); return true; }
/** * Finalize the block; mark it closed for modification * * @param ContextInterface $context * @param int $endLineNumber */ public function finalize(ContextInterface $context, $endLineNumber) { if (!$this->open) { return; // TODO: Throw AlreadyClosedException? } $this->open = false; $this->endLine = $endLineNumber; $context->setTip($context->getTip()->parent()); }
/** * @param ContextInterface $context * @param Cursor $cursor */ public function handleRemainingContents(ContextInterface $context, Cursor $cursor) { $cursor->advanceToFirstNonSpace(); $context->getTip()->addLine($cursor->getRemainder()); }
/** * @param ContextInterface $context * @param Cursor $cursor */ public function handleRemainingContents(ContextInterface $context, Cursor $cursor) { /** @var FencedCode $container */ $container = $context->getContainer(); // check for closing code fence if ($cursor->getIndent() <= 3 && $cursor->getFirstNonSpaceCharacter() == $container->getChar()) { $match = RegexHelper::matchAll('/^(?:`{3,}|~{3,})(?= *$)/', $cursor->getLine(), $cursor->getFirstNonSpacePosition()); if (strlen($match[0]) >= $container->getLength()) { // don't add closing fence to container; instead, close it: $this->setLength(-1); // -1 means we've passed closer return; } } $context->getTip()->addLine($cursor->getRemainder()); }
/** * @return bool */ public function areAllClosed() { return $this->context->getTip() === $this->lastMatchedContainer; }
/** * @param ContextInterface $context * @param Cursor $cursor */ public function handleRemainingContents(ContextInterface $context, Cursor $cursor) { // create paragraph container for line $context->addBlock(new Paragraph()); $cursor->advanceToFirstNonSpace(); $context->getTip()->addLine($cursor->getRemainder()); }
/** * @param ContextInterface $context * @param Cursor $cursor * * @return bool */ private function isLazyParagraphContinuation(ContextInterface $context, Cursor $cursor) { return !$context->getBlockCloser()->areAllClosed() && !$cursor->isBlank() && $context->getTip() instanceof Paragraph && count($context->getTip()->getStrings()) > 0; }
/** * Finalize the block; mark it closed for modification * * @param ContextInterface $context */ public function finalize(ContextInterface $context) { if (!$this->open) { return; // TODO: Throw AlreadyClosedException? } $this->open = false; if ($context->getLineNumber() > $this->getStartLine()) { $this->endLine = $context->getLineNumber() - 1; } else { $this->endLine = $context->getLineNumber(); } $context->setTip($context->getTip()->getParent()); }
/** * @param ContextInterface $context * @param Cursor $cursor */ public function handleRemainingContents(ContextInterface $context, Cursor $cursor) { $context->getTip()->addLine($cursor->getRemainder()); // Check for end condition if ($this->type >= self::TYPE_1_CODE_CONTAINER && $this->type <= self::TYPE_5_CDATA) { if ($cursor->match(RegexHelper::getHtmlBlockCloseRegex($this->type)) !== null) { $this->finalize($context, $context->getLineNumber()); } } }