@@ -180,9 +180,16 @@ protected static function highlightFile(string $file, int $lineNumber, int $line
180180 return false ;
181181 }
182182
183- $ source = str_replace (["\r\n" , "\r" ], "\n" , $ source );
184- $ source = explode ("\n" , highlight_string ($ source , true ));
185- $ source = str_replace ('<br /> ' , "\n" , $ source [1 ]);
183+ if (version_compare (PHP_VERSION , '8.3.0 ' , '< ' )) {
184+ $ source = str_replace (["\r\n" , "\r" ], "\n" , $ source );
185+ $ source = explode ("\n" , highlight_string ($ source , true ));
186+ $ source = str_replace ('<br /> ' , "\n" , $ source [1 ]);
187+ } else {
188+ $ source = highlight_string ($ source , true );
189+ // We have to remove these tags since we're preparing the result
190+ // ourselves and these tags are added manually at the end.
191+ $ source = str_replace (['<pre><code> ' , '</code></pre> ' ], '' , $ source );
192+ }
186193 $ source = explode ("\n" , str_replace ("\r\n" , "\n" , $ source ));
187194
188195 // Get just the part to show
@@ -199,7 +206,7 @@ protected static function highlightFile(string $file, int $lineNumber, int $line
199206 // of open and close span tags on one line, we need
200207 // to ensure we can close them all to get the lines
201208 // showing correctly.
202- $ spans = 1 ;
209+ $ spans = 0 ;
203210
204211 foreach ($ source as $ n => $ row ) {
205212 $ spans += substr_count ($ row , '<span ' ) - substr_count ($ row , '</span ' );
@@ -216,6 +223,9 @@ protected static function highlightFile(string $file, int $lineNumber, int $line
216223 );
217224 } else {
218225 $ out .= sprintf ('<span class="line"><span class="number"> ' . $ format . '</span> %s ' , $ n + $ start + 1 , $ row ) . "\n" ;
226+ // We're closing only one span tag we added manually line before,
227+ // so we have to increment $spans count to close this tag later.
228+ $ spans ++;
219229 }
220230 }
221231
0 commit comments