Просмотр файла vendor/league/commonmark/src/Extension/Attributes/Parser/AttributesBlockParser.php

Размер файла: 1.2Kb
  1. <?php
  2.  
  3. /*
  4. * This file is part of the league/commonmark package.
  5. *
  6. * (c) Colin O'Dell <colinodell@gmail.com>
  7. * (c) 2015 Martin Hasoň <martin.hason@gmail.com>
  8. *
  9. * For the full copyright and license information, please view the LICENSE
  10. * file that was distributed with this source code.
  11. */
  12.  
  13. declare(strict_types=1);
  14.  
  15. namespace League\CommonMark\Extension\Attributes\Parser;
  16.  
  17. use League\CommonMark\Block\Parser\BlockParserInterface;
  18. use League\CommonMark\ContextInterface;
  19. use League\CommonMark\Cursor;
  20. use League\CommonMark\Extension\Attributes\Node\Attributes;
  21. use League\CommonMark\Extension\Attributes\Util\AttributesHelper;
  22.  
  23. final class AttributesBlockParser implements BlockParserInterface
  24. {
  25. public function parse(ContextInterface $context, Cursor $cursor): bool
  26. {
  27. $state = $cursor->saveState();
  28. $attributes = AttributesHelper::parseAttributes($cursor);
  29. if ($attributes === []) {
  30. return false;
  31. }
  32.  
  33. if ($cursor->getNextNonSpaceCharacter() !== null) {
  34. $cursor->restoreState($state);
  35.  
  36. return false;
  37. }
  38.  
  39. $context->addBlock(new Attributes($attributes));
  40. $context->setBlocksParsed(true);
  41.  
  42. return true;
  43. }
  44. }