protected static function createFromLines()

in src/unparsed-blocks/FencedCodeBlock.php [44:91]


  protected static function createFromLines(
    vec<string> $lines,
    int $column,
    bool $eof,
  ): this {
    $first = C\firstx($lines);
    $matches = Regex\first_match($first, self::getPattern());
    invariant($matches is nonnull, 'Invalid first line');
    $info = Str\trim($matches['info'] ?? '');
    if ($info === '') {
      $info = null;
    } else {
      $new_info = '';
      $len = Str\length($info);
      for ($i = 0; $i < $len; ++$i) {
        $char = $info[$i];
        if (
          $char === "\\"
          && $i + 1 < $len
        ) {
          $next = $info[$i + 1];
          if (C\contains_key(ASCII_PUNCTUATION, $next)) {
            $new_info .= $next;
            ++$i;
            continue;
          }
        }
        if ($char === '&') {
          $result = decode_html_entity(Str\slice($info, $i));
          if ($result !== null) {
            list($match, $entity, $_rest) = $result;
            $new_info .= $entity;
            $i += Str\length($match) - 1;
            continue;
          }
        }
        $new_info .= $char;
      }
      $info = $new_info;
    }
    $indent = Str\length($matches['indent']);

    $content = $lines
      |> Vec\slice($$, 1, C\count($lines) - ($eof ? 1 : 2))
      |> Vec\map($$, $line ==> self::unindentLine($line, $indent, $column))
      |> Str\join($$, "\n");
    return new static($content, $info);
  }