in src/_Private/consume_link_title.php [78:121]
function consume_parenthesized_link_title(string $input): ?(string, int) {
invariant($input[0] === '(', 'must start with paren');
$len = Str\length($input);
$title = '';
$depth = 0;
for ($idx = 0; $idx < $len; ++$idx) {
$chr = $input[$idx];
if ($chr === "\n" && ($chr[$idx + 1] ?? null) === "\n") {
return null;
}
if ($chr === '(') {
++$depth;
continue;
}
if ($chr === ')') {
--$depth;
if ($depth === 0) {
break;
}
continue;
}
if ($chr === "\\") {
if ($idx + 1 < $len) {
$next = $input[$idx + 1];
if (C\contains_key(ASCII_PUNCTUATION, $next)) {
$title .= $next;
++$idx;
continue;
}
}
}
$title .= $chr;
}
if ($depth !== 0) {
return null;
}
return tuple($title, $idx + 1);
}