Skip to content
This repository was archived by the owner on Nov 23, 2026. It is now read-only.

Commit 5030aa6

Browse files
committed
Keep backtick spans intact before an underscore in doc_link
1 parent e254e14 commit 5030aa6

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎admin/filters/doc_link.php‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,12 @@ function after_filter_doc_link(string $data, string $folder): ?string
266266
$data = preg_replace('/:ref:`([^`]+)`_?/', '[$1]', $data);
267267
$data = preg_replace('/:doc:`([^`]+)`_?/', '[$1]', $data);
268268

269-
$data = preg_replace('/(?<!`)`([^`\n]+)`_/', '[$1]', $data);
269+
// Whole code spans are consumed so a closing backtick cannot open a reference before a "_".
270+
$data = preg_replace_callback('/(`+)([^\n]+?)(?<!`)\1(?!`)(_?)/', function (array $matches): string {
271+
return $matches[1] === '`' && $matches[3] === '_'
272+
? sprintf('[%s]', $matches[2])
273+
: $matches[0];
274+
}, $data);
270275

271276
$data = preg_replace('/{{EXTERNAL_LINK_START}}([^{]+){{EXTERNAL_LINK_MIDDLE}}([^{]+){{EXTERNAL_LINK_END}}/', '[$2]($1)', $data);
272277

0 commit comments

Comments
 (0)