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 13declare(strict_types=1); 14 15namespace League\CommonMark\Extension\Attributes\Parser; 16 17use League\CommonMark\Extension\Attributes\Util\AttributesHelper; 18use League\CommonMark\Parser\Block\BlockStart; 19use League\CommonMark\Parser\Block\BlockStartParserInterface; 20use League\CommonMark\Parser\Cursor; 21use League\CommonMark\Parser\MarkdownParserStateInterface; 22 23final class AttributesBlockStartParser implements BlockStartParserInterface 24{ 25 public function tryStart(Cursor $cursor, MarkdownParserStateInterface $parserState): ?BlockStart 26 { 27 $originalPosition = $cursor->getPosition(); 28 $attributes = AttributesHelper::parseAttributes($cursor); 29 30 if ($attributes === [] && $originalPosition === $cursor->getPosition()) { 31 return BlockStart::none(); 32 } 33 34 if ($cursor->getNextNonSpaceCharacter() !== null) { 35 return BlockStart::none(); 36 } 37 38 return BlockStart::of(new AttributesBlockContinueParser($attributes, $parserState->getActiveBlockParser()->getBlock()))->at($cursor); 39 } 40} 41