private function incorporateLine(ContextInterface $context) { $cursor = new Cursor($context->getLine()); $context->getBlockCloser()->resetTip(); $context->setBlocksParsed(false); $this->resetContainer($context, $cursor); $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()); } $this->parseBlocks($context, $cursor); // What remains at the offset is a text line. Add the text to the appropriate container. // First check for a lazy paragraph continuation: if ($this->isLazyParagraphContinuation($context, $cursor)) { // lazy paragraph continuation $context->getTip()->addLine($cursor->getRemainder()); return; } // 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()); } }
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()); } } }