private static function consumeRow()

in src/unparsed-blocks/TableExtension.php [125:185]


  private static function consumeRow(
    Context $context,
    Lines $lines,
  ): ?(bool, vec<string>, Lines) {
    list($first, $rest) = $lines->getFirstLineAndRest();

    $definitely_row = false;

    if (Str\starts_with($first, '|')) {
      $definitely_row = true;
      $first = Str\slice($first, 1);
    }
    if (Str\ends_with($first, '|')) {
      $definitely_row = true;
      $first = Str\slice($first, 0, Str\length($first) - 1);
    }

    $parts = vec[];
    $start = 0;
    $len = Str\length($first);
    while ($start !== null && $start < $len) {
      $end = Str\search($first, '|', $start);
      if ($end === null) {
        $parts[] = Str\slice($first, $start);
        break;
      }

      while ($end !== null && $end > 1 && $first[(int) $end - 1] === '\\') {
        $end = Str\search($first, '|', $end + 1);
      }

      if ($end === null) {
        $parts[] = Str\slice($first, $start);
        break;
      }

      $parts[] = Str\slice($first, $start, $end - $start);
      $start = $end + 1;
    }

    $definitely_row = $definitely_row || C\count($parts) >= 2;

    if (!$definitely_row) {
      $is_continuation = _Private\is_paragraph_continuation_text(
        $context,
        $lines,
      );
      if (!$is_continuation) {
        return null;
      }
    }

    return tuple(
      $definitely_row,
      Vec\map(
        $parts,
        $part ==> Str\trim($part) |> Str\replace($$, "\\|", '|'),
      ),
      $rest,
    );
  }