File tree 1 file changed +12
-10
lines changed
1 file changed +12
-10
lines changed Original file line number Diff line number Diff line change 15
15
final class IndentedCodeBlockRenderer implements NodeRendererInterface
16
16
{
17
17
public function __construct (
18
- private ? Highlighter $ highlighter = new Highlighter () ,
19
- ) {
20
- }
18
+ private Highlighter $ highlighter ,
19
+ private string $ defaultLanguage = ' php '
20
+ ) { }
21
21
22
22
public function render (Node $ node , ChildNodeRendererInterface $ childRenderer )
23
23
{
24
24
if (! $ node instanceof IndentedCode) {
25
- throw new InvalidArgumentException ('Block must be instance of ' . IndentedCode::class);
25
+ throw new InvalidArgumentException ('Block must be instance of ' . IndentedCode::class);
26
26
}
27
-
28
- $ highlighter = $ this ->highlighter ;
29
27
30
- $ language = ' php ' ;
28
+ $ highlighter = $ this -> highlighter ;
31
29
32
- $ parsed = $ highlighter ->parse ($ node ->getLiteral (), $ language );
30
+ $ parsed = $ highlighter ->parse ($ node ->getLiteral (), $ this -> defaultLanguage );
33
31
34
32
$ theme = $ highlighter ->getTheme ();
35
33
36
34
if ($ theme instanceof WebTheme) {
37
- return $ theme ->preBefore ($ highlighter ) . $ parsed . $ theme ->preAfter ($ highlighter );
35
+ return $ theme ->preBefore ($ highlighter ). $ parsed. $ theme ->preAfter ($ highlighter );
38
36
}
39
37
40
- return sprintf ('<pre data-lang="%s" class="notranslate">%s</pre> ' , $ language , $ parsed );
38
+ return sprintf (
39
+ '<pre><code data-lang="%s" class="notranslate">%s</code></pre> ' ,
40
+ $ this ->defaultLanguage ,
41
+ $ parsed
42
+ );
41
43
}
42
44
}
You can’t perform that action at this time.
0 commit comments