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

Commit 3575f00

Browse files
committed
Unwrap blockquotes left by indented RST text
1 parent c8dc944 commit 3575f00

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

‎admin/filters/alerts.php‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ function after_filter_alerts(string $data, string $folder): ?string {
1414
$result = preg_replace('/^ > ``` /m', ' ``` ', $result);
1515
$result = preg_replace('/^ > ([^!])/m', ' $1', $result);
1616

17-
$result = preg_replace('/^> (?!\d+\.|!)/', ' ', $result);
17+
// Sphinx renders indented RST text as a plain block, not a quotation.
18+
do {
19+
$result = preg_replace('/^([ \t]*)>(?: |$)/m', '$1', $result, -1, $count);
20+
} while ($result !== null && $count > 0);
1821

19-
return preg_replace('/^> (\d+\.\s+)/m', '$1', $result);
22+
return $result;
2023
}

‎admin/filters/includes.php‎

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

55
/**
6-
* Samples held back from the other filters, keyed by the number in their `CI4SAMPLE<n>` marker.
6+
* Samples held back from the other filters, keyed by the number in their `CodeBlockPlaceholder<n>` marker.
77
*
88
* @return list<array{language: string, lines: list<string>}>
99
*/
@@ -14,7 +14,7 @@ function &includedSamples(): array {
1414
}
1515

1616
/**
17-
* Replaces each `literalinclude` and `code-block` with a `CI4SAMPLE<n>` marker line at the directive's indentation.
17+
* Replaces each `literalinclude` and `code-block` with a `CodeBlockPlaceholder<n>` marker line at the directive's indentation.
1818
*/
1919
function before_filter_includes(string $data, string $folder): ?string {
2020
$samples = &includedSamples();
@@ -44,7 +44,7 @@ function before_filter_includes(string $data, string $folder): ?string {
4444
$body[] = $lines[++$i];
4545
}
4646

47-
array_push($result, $indent . 'CI4SAMPLE' . count($samples), '');
47+
array_push($result, sprintf('%sCodeBlockPlaceholder%d', $indent, count($samples)), '');
4848
$samples[] = ['language' => $matches[3], 'lines' => dedentLines(trimBlankLines($body))];
4949

5050
continue;
@@ -53,7 +53,7 @@ function before_filter_includes(string $data, string $folder): ?string {
5353
$file = str_starts_with($matches[3], '/') ? rtrim(SOURCE_DIR, '/') . $matches[3] : $folder . '/' . $matches[3];
5454

5555
if (! is_file($file)) {
56-
fwrite(STDERR, "Warning: sample {$matches[3]} not found for literalinclude in {$folder}\n");
56+
fwrite(STDERR, sprintf("Warning: sample %s not found for literalinclude in %s\n", $matches[3], $folder));
5757
array_push($result, ...$directive);
5858

5959
continue;
@@ -65,22 +65,21 @@ function before_filter_includes(string $data, string $folder): ?string {
6565
$sample = selectSampleLines($sample, $options['lines']);
6666
}
6767

68-
$result[] = $indent . 'CI4SAMPLE' . count($samples);
68+
$result[] = sprintf('%sCodeBlockPlaceholder%d', $indent, count($samples));
6969
$samples[] = ['language' => $options['language'] ?? 'php', 'lines' => trimBlankLines($sample)];
7070
}
7171

7272
return implode("\n", $result);
7373
}
7474

7575
/**
76-
* Replaces each `CI4SAMPLE<n>` marker line with its sample as a fenced block, prefixed like the marker.
76+
* Replaces each `CodeBlockPlaceholder<n>` marker line with its sample as a fenced block, prefixed like the marker.
7777
*/
7878
function after_filter_includes(string $data, string $folder): ?string {
7979
$samples = &includedSamples();
8080

81-
return preg_replace_callback('/^(.*?)CI4SAMPLE(\d+)[ \t]*$/m', function (array $matches) use ($samples): string {
82-
// Sphinx renders an indented sample outside any container as a plain block, not a blockquote.
83-
$prefix = preg_replace('/> ?/', '', $matches[1]);
81+
return preg_replace_callback('/^(.*?)CodeBlockPlaceholder(\d+)[ \t]*$/m', function (array $matches) use ($samples): string {
82+
$prefix = $matches[1];
8483
$sample = $samples[(int) $matches[2]];
8584

8685
preg_match_all('/`+/', implode("\n", $sample['lines']), $runs);

0 commit comments

Comments
 (0)