@@ -182,8 +182,15 @@ protected static function highlightFile(string $file, int $lineNumber, int $line
182182
183183 $ source = str_replace (["\r\n" , "\r" ], "\n" , $ source );
184184 $ source = explode ("\n" , highlight_string ($ source , true ));
185- $ source = str_replace ('<br /> ' , "\n" , $ source [1 ]);
186- $ source = explode ("\n" , str_replace ("\r\n" , "\n" , $ source ));
185+
186+ if (PHP_VERSION_ID < 80300 ) {
187+ $ source = str_replace ('<br /> ' , "\n" , $ source [1 ]);
188+ $ source = explode ("\n" , str_replace ("\r\n" , "\n" , $ source ));
189+ } else {
190+ // We have to remove these tags since we're preparing the result
191+ // ourselves and these tags are added manually at the end.
192+ $ source = str_replace (['<pre><code> ' , '</code></pre> ' ], '' , $ source );
193+ }
187194
188195 // Get just the part to show
189196 $ start = max ($ lineNumber - (int ) round ($ lines / 2 ), 0 );
@@ -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