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

Commit 334e401

Browse files
committed
Escape underscores that start a path segment
1 parent 7717937 commit 334e401

3 files changed

Lines changed: 19 additions & 0 deletions

File tree

‎admin/convert.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ function load_filters(): array
5555
'doc_link',
5656
'class_reference',
5757
'list_indentation',
58+
'underscores',
5859
];
5960
$afterFilters = [
6061
'images',

‎admin/filters/underscores.php‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* Escapes the underscore that starts a path segment, which pandoc 3.13 reads as an RST inline target.
7+
*/
8+
function before_filter_underscores(string $data, string $folder): ?string
9+
{
10+
return preg_replace_callback('/(``.+?``)|\S+/', function (array $matches): string {
11+
if (isset($matches[1]) || str_contains($matches[0], '://') || str_contains($matches[0], '](')) {
12+
return $matches[0];
13+
}
14+
15+
return preg_replace('#(?<=/)_(?=\w)#', '\\\\_', $matches[0]);
16+
}, $data);
17+
}

‎admin/how_to_use_filters.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ all before filters on every page, then pandoc on every page, then all after filt
2727
| `doc_link` | Converts `:doc:`, `:ref:` and `:php:*:` roles, external links and `\|version\|` | Unescapes the link syntax and converts `title-ref` and label spans |
2828
| `class_reference` | Converts `php:namespace`, `php:class`, `php:method`, `php:function`, `php:attr` and their fields into headings and lists | Unescapes `\#` |
2929
| `list_indentation` | Adds the blank line that pandoc needs between a directive and a list that starts its body | Re-indents nested lists by four spaces per level and adds the blank line that Python-Markdown needs before a list |
30+
| `underscores` | Escapes the underscore that starts a path segment, such as `tests/_support`, which pandoc 3.13 reads as an inline target | |
3031
| `images` | | Converts image tags to Markdown |
3132
| `alerts` | | Converts `> [!NOTE]` alerts and unwraps the blockquotes left by indented RST text |
3233
| `dollar_sign` | | Unescapes `\$` |

0 commit comments

Comments
 (0)