public static function consume()

in src/unparsed-blocks/LinkReferenceDefinition.php [52:108]


  public static function consume(
    Context $context,
    Lines $lines,
  ): ?(Block, Lines) {
    if ($context->isInParagraphContinuation()) {
      return null;
    }

    $label = self::consumeLabel($lines);
    if ($label === null) {
      return null;
    }
    list($label, $lines) = $label;

    $first = $lines->getFirstLine();
    if (($first[0] ?? null) !== ':') {
      return null;
    }

    $lines = $lines->withoutFirstLinePrefix(':');

    $result = self::consumeOptionalWhitespaceAndDestination($lines);
    if ($result === null) {
      return null;
    }

    list($destination, $lines) = $result;
    if (!$context->areAllURISchemesEnabled()) {
      $allowed_uri_schemes = $context->getAllowedURISchemes();
      if (
        !C\any($allowed_uri_schemes, $elem ==> Str\starts_with_ci($destination, $elem.':'))
      ) {
        return null;
      }
    }
    $title = self::consumeWhitespaceAndTitle($lines);
    if ($title !== null) {
      list($title, $rest) = $title;
      if (self::consumeEnd($rest) === null) {
        $title = null;
      } else {
        $lines = $rest;
      }
    } else {
      // refine from ?(tuple|string) to ?string
      $title = null;
    }

    $lines = self::consumeEnd($lines);
    if ($lines === null) {
      return null;
    }

    $def = new self($label, $destination, $title);
    $context->addLinkReferenceDefinition($def);
    return tuple($def, $lines);
  }