getBlockCloser() public method

Finalize and close any unmatched blocks
public getBlockCloser ( ) : UnmatchedBlockCloser
return UnmatchedBlockCloser
 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;
 }
Beispiel #2
0
 private function incorporateLine(ContextInterface $context)
 {
     $cursor = new Cursor($context->getLine());
     $context->getBlockCloser()->resetTip();
     $context->setBlocksParsed(false);
     $context->setContainer($context->getDocument());
     while ($context->getContainer()->hasChildren()) {
         $lastChild = $context->getContainer()->getLastChild();
         if (!$lastChild->isOpen()) {
             break;
         }
         $context->setContainer($lastChild);
         if (!$context->getContainer()->matchesNextLine($cursor)) {
             $context->setContainer($context->getContainer()->getParent());
             // back up to the last matching block
             break;
         }
     }
     $context->getBlockCloser()->setLastMatchedContainer($context->getContainer());
     // Check to see if we've hit 2nd blank line; if so break out of list:
     if ($cursor->isBlank() && $context->getContainer()->endsWithBlankLine()) {
         $this->breakOutOfLists($context, $context->getContainer());
     }
     while (!$context->getContainer()->isCode() && !$context->getBlocksParsed()) {
         $parsed = false;
         foreach ($this->environment->getBlockParsers() as $parser) {
             if ($parser->parse($context, $cursor)) {
                 $parsed = true;
                 break;
             }
         }
         if (!$parsed || $context->getContainer()->acceptsLines()) {
             $context->setBlocksParsed(true);
         }
     }
     // What remains at the offset is a text line.  Add the text to the appropriate container.
     // First check for a lazy paragraph continuation:
     if (!$context->getBlockCloser()->areAllClosed() && !$cursor->isBlank() && $context->getTip() instanceof Paragraph && count($context->getTip()->getStrings()) > 0) {
         // lazy paragraph continuation
         $context->getTip()->addLine($cursor->getRemainder());
     } else {
         // not a lazy continuation
         // finalize any blocks not matched
         $context->getBlockCloser()->closeUnmatchedBlocks();
         // Determine whether the last line is blank, updating parents as needed
         $context->getContainer()->setLastLineBlank($cursor, $context->getLineNumber());
         // Handle any remaining cursor contents
         if ($context->getContainer()->isOpen()) {
             $context->getContainer()->handleRemainingContents($context, $cursor);
         } elseif (!$cursor->isBlank()) {
             // Create paragraph container for line
             $context->addBlock(new Paragraph());
             $cursor->advanceToFirstNonSpace();
             $context->getTip()->addLine($cursor->getRemainder());
         }
     }
 }
Beispiel #3
0
 /**
  * @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;
 }