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

Commit 49f63f9

Browse files
committed
Escape underscores that start a name
1 parent 793dd43 commit 49f63f9

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎admin/filters/underscores.php‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
declare(strict_types=1);
44

55
/**
6-
* Escapes the underscore that starts a path segment and the `::` between two words, which pandoc 3.13 reads as an RST inline target and as a link.
6+
* Escapes the underscore that starts a name or path segment and the `::` between two words, which pandoc 3.13 reads as an RST inline target and as a link.
77
*/
88
function before_filter_underscores(string $data, string $folder): ?string
99
{
@@ -28,12 +28,16 @@ function before_filter_underscores(string $data, string $folder): ?string
2828

2929
function escape_inline_targets(string $line): string
3030
{
31+
if (preg_match('/^\s*\.\. _/', $line) === 1) {
32+
return $line;
33+
}
34+
3135
return preg_replace_callback('/(`[^`]+`|``.+?``)|[^\s`]+/', function (array $matches): string {
3236
if (isset($matches[1]) || str_contains($matches[0], '://') || str_contains($matches[0], '](')) {
3337
return $matches[0];
3438
}
3539

36-
return preg_replace(['#(?<=/)_(?=\w)#', '/(?<=\w)::(?=\w)/'], ['\\\\_', '\\\\::'], $matches[0]);
40+
return preg_replace(['/(?<![\w\\\\$])_(?=[A-Za-z])/', '/(?<=\w)::(?=\w)/'], ['\\\\_', '\\\\::'], $matches[0]);
3741
}, $line);
3842
}
3943

0 commit comments

Comments
 (0)