public static function consume()

in src/unparsed-blocks/ATXHeading.php [22:49]


  public static function consume(
    Context $_context,
    Lines $lines,
  ): ?(Block, Lines) {
    $patterns = vec[
      re"/^ {0,3}(?<level>#{1,6})([ \\t](?<title>.*))?[ \\t]+#+[ \\t]*$/",
      re"/^ {0,3}(?<level>#{1,6})([ \\t](?<title>.*))?$/",
    ];

    list($first, $rest) = $lines->getFirstLineAndRest();

    $title = null;
    $level = null;
    foreach ($patterns as $pattern) {
      $matches = Regex\first_match($first, $pattern);
      if ($matches is nonnull) {
        $title = $matches['title'] ?? '';
        $level = Str\length($matches['level']);
        break;
      }
    }

    if ($title is null || $level is null) {
      return null;
    }

    return tuple(new self($level, Str\trim($title)), $rest);
  }