vendor/league/commonmark/src/Extension/CommonMark/Parser/Block/FencedCodeStartParser.php line 38

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of the league/commonmark package.
  5.  *
  6.  * (c) Colin O'Dell <colinodell@gmail.com>
  7.  *
  8.  * For the full copyright and license information, please view the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace League\CommonMark\Extension\CommonMark\Parser\Block;
  12. use League\CommonMark\Parser\Block\BlockStart;
  13. use League\CommonMark\Parser\Block\BlockStartParserInterface;
  14. use League\CommonMark\Parser\Cursor;
  15. use League\CommonMark\Parser\MarkdownParserStateInterface;
  16. final class FencedCodeStartParser implements BlockStartParserInterface
  17. {
  18.     public function tryStart(Cursor $cursorMarkdownParserStateInterface $parserState): ?BlockStart
  19.     {
  20.         if ($cursor->isIndented() || ! \in_array($cursor->getNextNonSpaceCharacter(), ['`''~'], true)) {
  21.             return BlockStart::none();
  22.         }
  23.         $indent $cursor->getIndent();
  24.         $fence  $cursor->match('/^[ \t]*(?:`{3,}(?!.*`)|~{3,})/');
  25.         if ($fence === null) {
  26.             return BlockStart::none();
  27.         }
  28.         // fenced code block
  29.         $fence \ltrim($fence" \t");
  30.         return BlockStart::of(new FencedCodeParser(\strlen($fence), $fence[0], $indent))->at($cursor);
  31.     }
  32. }