public static function consume()

in src/inlines/CodeSpan.php [29:69]


  public static function consume(
    Context $_,
    string $string,
    int $offset,
  ): ?(this, int) {
    if ($offset > 0 && $string[$offset - 1] === '`') {
      return null;
    }

    if ($string[$offset] !== '`') {
      return null;
    }

    $start = StrPos\trim_left($string, $offset, '`');
    $marker_len = $start - $offset;
    $marker = Str\repeat('`', $marker_len);
    $end = Str\search($string, $marker, $start);

    $len = Str\length($string);
    while (
      $end !== null
      && (
        ($end + $marker_len < $len && $string[$end + $marker_len] === '`')
        || $string[$end - 1] === '`'
      )
    ) {
      $end = Str\search($string, $marker, $end + 1);
    }
    if ($end === null) {
      return null;
    }

    return tuple(
      new static(
        Str\slice($string, $start, $end - $start)
        |> Str\trim($$)
        |> \preg_replace('/\s+/m', ' ', $$),
      ),
      $end + $marker_len,
    );
  }