/** * @param \League\CommonMark\ContextInterface $context * @param \League\CommonMark\InlineParserContext $inlineContext * @return bool */ public function parse(ContextInterface $context, InlineParserContext $inlineContext) { $this->context = $context; $this->inlineContext = $inlineContext; $this->cursor = $inlineContext->getCursor(); $this->originalState = $this->cursor->saveState(); $this->cursor->advance(); return $this->parseMediaType(); }
public function matchesNextLine(Cursor $cursor) { if ($cursor->getIndent() <= 3 && $cursor->getFirstNonSpaceCharacter() === '>') { $cursor->advanceToFirstNonSpace(); $cursor->advance(); if ($cursor->getCharacter() === ' ') { $cursor->advance(); } return true; } return false; }
/** * @param ContextInterface $context * @param Cursor $cursor * * @return bool */ public function parse(ContextInterface $context, Cursor $cursor) { if ($cursor->getFirstNonSpaceCharacter() !== '>') { return false; } $cursor->advanceToFirstNonSpace(); $cursor->advance(); if ($cursor->getCharacter() === ' ') { $cursor->advance(); } $context->addBlock(new BlockQuote()); return true; }
public function parse(ContextInterface $context, Cursor $cursor) { $inlineParserContext = new InlineParserContext($cursor); while (($character = $cursor->getCharacter()) !== null) { if ($matchingParsers = $this->environment->getInlineParsersForCharacter($character)) { foreach ($matchingParsers as $parser) { if ($parser->parse($context, $inlineParserContext)) { continue 2; } } } // We reach here if none of the parsers can handle the input // Attempt to match multiple non-special characters at once $text = $cursor->match($this->environment->getInlineParserCharacterRegex()); // This might fail if we're currently at a special character which wasn't parsed; if so, just add that character if ($text === null) { $cursor->advance(); $text = $character; } $lastInline = $inlineParserContext->getInlines()->last(); if ($lastInline instanceof Text && !isset($lastInline->data['delim'])) { $lastInline->append($text); } else { $inlineParserContext->getInlines()->add(new Text($text)); } } foreach ($this->environment->getInlineProcessors() as $inlineProcessor) { $inlineProcessor->processInlines($inlineParserContext->getInlines(), $inlineParserContext->getDelimiterStack()); } return $inlineParserContext->getInlines(); }
public function matchesNextLine(Cursor $cursor) { if (!$cursor->isIndented() && $cursor->getFirstNonSpaceCharacter() === '>') { $cursor->advanceToFirstNonSpace(); $cursor->advance(); $cursor->advanceBySpaceOrTab(); return true; } return false; }
public function matchesNextLine(Cursor $cursor) { if ($cursor->getIndent() <= 3 && in_array($cursor->getFirstNonSpaceCharacter(), static::getIconBlockTypes())) { $cursor->advanceToFirstNonSpace(); if ($cursor->peek() === '>') { $cursor->advanceBy(2); if ($cursor->getCharacter() === ' ') { $cursor->advance(); } return true; } } return false; }
/** * @param ContextInterface $context * @param Cursor $cursor * * @return bool */ public function parse(ContextInterface $context, Cursor $cursor) { if ($cursor->getFirstNonSpaceCharacter() !== 'A' || $cursor->getCharacter($cursor->getFirstNonSpacePosition() + 1) !== '>') { return false; } $cursor->advanceToFirstNonSpace(); if ($cursor->peek() === '>') { $cursor->advanceBy(2); if ($cursor->getCharacter() === ' ') { $cursor->advance(); } } $context->addBlock(new Aside()); return true; }
/** * @param ContextInterface $context * @param Cursor $cursor * * @return bool */ public function parse(ContextInterface $context, Cursor $cursor) { if (!in_array($cursor->getFirstNonSpaceCharacter(), IconBlock::getIconBlockTypes()) || $cursor->getCharacter($cursor->getFirstNonSpacePosition() + 1) !== '>') { return false; } $type = $cursor->getFirstNonSpaceCharacter(); $cursor->advanceToFirstNonSpace(); if ($cursor->peek() === '>') { $cursor->advanceBy(2); if ($cursor->getCharacter() === ' ') { $cursor->advance(); } } $context->addBlock(new IconBlock($type)); return true; }
/** * @param Cursor $cursor * * @return array|bool */ protected function tryParseInlineLinkAndTitle(Cursor $cursor) { $cursor->advance(); $cursor->advanceToFirstNonSpace(); if (($dest = LinkParserHelper::parseLinkDestination($cursor)) === null) { return false; } $cursor->advanceToFirstNonSpace(); $title = null; // make sure there's a space before the title: if (preg_match('/^\\s/', $cursor->peek(-1))) { $title = LinkParserHelper::parseLinkTitle($cursor) ?: ''; } $cursor->advanceToFirstNonSpace(); if (!$cursor->match('/^\\)/')) { return false; } return ['url' => $dest, 'title' => $title]; }
/** * @param Cursor $cursor * * @return array|bool */ protected function tryParseInlineLinkAndTitle(Cursor $cursor) { if ($cursor->getCharacter() !== '(') { return false; } $previousState = $cursor->saveState(); $cursor->advance(); $cursor->advanceToFirstNonSpace(); if (($dest = LinkParserHelper::parseLinkDestination($cursor)) === null) { $cursor->restoreState($previousState); return false; } $cursor->advanceToFirstNonSpace(); $title = null; // make sure there's a space before the title: if (preg_match(RegexHelper::REGEX_WHITESPACE_CHAR, $cursor->peek(-1))) { $title = LinkParserHelper::parseLinkTitle($cursor) ?: ''; } $cursor->advanceToFirstNonSpace(); if ($cursor->match('/^\\)/') === null) { $cursor->restoreState($previousState); return false; } return ['url' => $dest, 'title' => $title]; }