in src/inlines/Link.php [226:272]
private static function consumeDestinationAndTitle(
string $markdown,
int $offset,
): ?(string, ?string, int) {
$len = Str\length($markdown);
if ($offset === $len || $markdown[$offset] !== '(') {
return null;
}
$offset++;
$maybe_offset = StrPos\trim_left($markdown, $offset);
$slice = Str\slice($markdown, $maybe_offset);
$destination = consume_link_destination($slice);
if ($destination !== null) {
list($destination, $consumed) = $destination;
} else {
$destination = '';
$consumed = 0;
}
$offset = StrPos\trim_left($markdown, $maybe_offset + $consumed);
if ($offset === $len) {
return null;
}
$slice = Str\slice($markdown, $offset);
$title = consume_link_title($slice);
if ($title !== null) {
list($title, $consumed) = $title;
$offset = StrPos\trim_left($markdown, $offset + $consumed);
} else {
// make title ?markdown, instead of markdown|?(markdown, markdown)
$title = null;
}
if ($offset === $len) {
return null;
}
if ($markdown[$offset] !== ')') {
return null;
}
return tuple($destination, $title, $offset + 1);
}