in src/inlines/AutoLinkExtension.php [32:88]
public static function consume(
Context $_,
string $markdown,
int $offset,
): ?(Inline, int) {
if (
$offset > 0
&& !C\contains_key(self::MUST_FOLLOW, $markdown[$offset - 1])
) {
return null;
}
$string = Str\slice($markdown, $offset);
$matches = darray[];
$result = \preg_match_with_matches(
'/^(?<prefix>'.self::PREFIX.')(?<domain>'.self::DOMAIN.')/i',
$string,
inout $matches,
);
if ($result !== 1) {
return null;
}
$full = $matches[0];
$offset += Str\length($full);
$prefix = $matches['prefix'];
$domain = $matches['domain'];
$next = $offset < Str\length($markdown) ? $markdown[$offset] : null;
if ($next === '-' || $next === '_') {
return null;
}
if (Str\lowercase($prefix) === 'www.') {
list($path, $offset) = self::consumePath($markdown, $offset);
$text = $prefix.$domain.$path;
return tuple(
new self($text, 'http://'.$text),
$offset,
);
}
if (Str\ends_with($prefix, '://')) {
list($path, $offset) = self::consumePath($markdown, $offset);
$text = $prefix.$domain.$path;
return tuple(
new self($text, $text),
$offset,
);
}
// email
return tuple(
new self($full, 'mailto:'.$full),
$offset,
);
}