setBlocksParsed() public method

public setBlocksParsed ( boolean $bool )
$bool boolean
Beispiel #1
0
 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());
     }
 }
 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
  *
  * @return bool
  */
 public function parse(ContextInterface $context, Cursor $cursor)
 {
     if (!$cursor->isIndented()) {
         return false;
     }
     $context->setBlocksParsed(true);
     return true;
 }
 /**
  * @param ContextInterface $context
  * @param Cursor $cursor
  *
  * @return bool
  */
 public function parse(ContextInterface $context, Cursor $cursor)
 {
     if ($cursor->getIndent() < IndentedCodeParser::CODE_INDENT_LEVEL) {
         return false;
     }
     $context->setBlocksParsed(true);
     return true;
 }
Beispiel #5
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());
         }
     }
 }
 /**
  * @param ContextInterface $context
  * @param Cursor $cursor
  *
  * @return bool
  */
 public function parse(ContextInterface $context, Cursor $cursor)
 {
     $match = RegexHelper::matchAt(RegexHelper::getInstance()->getHtmlBlockOpenRegex(), $cursor->getLine(), $cursor->getFirstNonSpacePosition());
     if ($match === null) {
         return false;
     }
     $context->addBlock(new HtmlBlock());
     $context->setBlocksParsed(true);
     return true;
 }
 /**
  * @param ContextInterface $context
  * @param Cursor           $cursor
  *
  * @return bool
  */
 public function parse(ContextInterface $context, Cursor $cursor)
 {
     if ($cursor->isIndented()) {
         return false;
     }
     $match = RegexHelper::matchAt(RegexHelper::getInstance()->getThematicBreakRegex(), $cursor->getLine(), $cursor->getFirstNonSpacePosition());
     if ($match === null) {
         return false;
     }
     // Advance to the end of the string, consuming the entire line (of the thematic break)
     $cursor->advanceBy(mb_strlen($cursor->getRemainder()));
     $context->addBlock(new ThematicBreak());
     $context->setBlocksParsed(true);
     return true;
 }
 public function parse(ContextInterface $context, Cursor $cursor)
 {
     $state = $cursor->saveState();
     $attributes = AttributesUtils::parse($cursor);
     if (empty($attributes)) {
         return false;
     }
     if (null !== $cursor->getFirstNonSpaceCharacter()) {
         $cursor->restoreState($state);
         return false;
     }
     $context->addBlock(new Attributes($attributes));
     $context->setBlocksParsed(true);
     return true;
 }
Beispiel #9
0
 /**
  * @param \League\CommonMark\ContextInterface $context
  * @param \League\CommonMark\Cursor $cursor
  *
  * @return bool
  */
 public function parse(\League\CommonMark\ContextInterface $context, \League\CommonMark\Cursor $cursor)
 {
     $line = $cursor->getLine();
     //either a line starting with 'example:' (expected to have a set of links)
     //or a line starting with [example] (a single link)
     //remove potential markdown formatting (except what we need)
     $check = preg_replace('#[^a-z:\\[\\]]#', '', strtolower($line));
     if (substr($check, 0, 8) != 'example:' and substr($check, 0, 9) != '[example]') {
         return false;
     }
     $context->addBlock(new ExampleElement($cursor->getLine(), $this->path));
     $cursor->advanceBy(strlen($line));
     $context->setBlocksParsed(true);
     return true;
 }
 /**
  * @param ContextInterface $context
  * @param Cursor $cursor
  *
  * @return bool
  */
 public function parse(ContextInterface $context, Cursor $cursor)
 {
     $match = RegexHelper::matchAll('/^#{1,6}(?: +|$)/', $cursor->getLine(), $cursor->getFirstNonSpacePosition());
     if (!$match) {
         return false;
     }
     $cursor->advanceToFirstNonSpace();
     $cursor->advanceBy(strlen($match[0]));
     $level = strlen(trim($match[0]));
     $str = $cursor->getRemainder();
     $str = preg_replace('/^ *#+ *$/', '', $str);
     $str = preg_replace('/ +#+ *$/', '', $str);
     $context->addBlock(new Header($level, $str));
     $context->setBlocksParsed(true);
     return true;
 }
 /**
  * @param ContextInterface $context
  * @param Cursor           $cursor
  *
  * @return bool
  */
 public function parse(ContextInterface $context, Cursor $cursor)
 {
     if ($cursor->isIndented()) {
         return false;
     }
     if ($cursor->getFirstNonSpaceCharacter() !== '<') {
         return false;
     }
     $savedState = $cursor->saveState();
     $cursor->advanceToFirstNonSpace();
     $line = $cursor->getRemainder();
     for ($blockType = 1; $blockType <= 7; $blockType++) {
         $match = RegexHelper::matchAt(RegexHelper::getHtmlBlockOpenRegex($blockType), $line);
         if ($match !== null && ($blockType < 7 || !$context->getContainer() instanceof Paragraph)) {
             $cursor->restoreState($savedState);
             $context->addBlock(new HtmlBlock($blockType));
             $context->setBlocksParsed(true);
             return true;
         }
     }
     $cursor->restoreState($savedState);
     return false;
 }