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; }
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; }
public function parse(ContextInterface $context, InlineParserContext $inlineContext) { $cursor = $inlineContext->getCursor(); if ($cursor->getFirstNonSpaceCharacter() !== '{') { return false; } $char = $cursor->getCharacter(); if ('{' === $char) { $char = (string) $cursor->getCharacter($cursor->getPosition() - 1); } $attributes = AttributesUtils::parse($cursor); if (empty($attributes)) { return false; } $inlineContext->getInlines()->add(new InlineAttributes($attributes, ' ' === $char || '' === $char)); return true; }
public function parse(InlineParserContext $inlineContext) { $cursor = $inlineContext->getCursor(); if ($cursor->getFirstNonSpaceCharacter() !== '{') { return false; } $char = $cursor->getCharacter(); if ('{' === $char) { $char = (string) $cursor->getCharacter($cursor->getPosition() - 1); } $attributes = AttributesUtils::parse($cursor); if (empty($attributes)) { return false; } if ('' === $char) { $cursor->advanceToFirstNonSpace(); } $node = new InlineAttributes($attributes, ' ' === $char || '' === $char); $inlineContext->getContainer()->appendChild($node); $inlineContext->getDelimiterStack()->push(new Delimiter('attributes', 1, $node, false, false)); return true; }