33declare (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 */
1919function 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 */
7878function 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