Skip to content

Commit

Permalink
[ErrorHandler] Fix rendered exception code highlighting on PHP 8.3
Browse files Browse the repository at this point in the history
  • Loading branch information
tscni committed Jun 9, 2024
1 parent c6c8f96 commit c25da5c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions ErrorRenderer/HtmlErrorRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,10 @@ private function fileExcerpt(string $file, int $line, int $srcContext = 3): stri
if (\PHP_VERSION_ID >= 80300) {
// remove main pre/code tags
$code = preg_replace('#^<pre.*?>\s*<code.*?>(.*)</code>\s*</pre>#s', '\\1', $code);
// split multiline code tags
$code = preg_replace_callback('#<code ([^>]++)>((?:[^<]*+\\n)++[^<]*+)</code>#', function ($m) {
return "<code $m[1]>".str_replace("\n", "</code>\n<code $m[1]>", $m[2]).'</code>';
// split multiline span tags
$code = preg_replace_callback('#<span ([^>]++)>((?:[^<\\n]*+\\n)++[^<]*+)</span>#', function ($m) {
return "<span $m[1]>".str_replace("\n", "</span>\n<span $m[1]>", $m[2]).'</span>';
}, $code);
// Convert spaces to html entities to preserve indentation when rendered
$code = str_replace(' ', '&nbsp;', $code);
$content = explode("\n", $code);
} else {
// remove main code/span tags
Expand Down
2 changes: 1 addition & 1 deletion Resources/assets/css/exception.css
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ header .container { display: flex; justify-content: space-between; }
.trace-code li { color: #969896; margin: 0; padding-left: 10px; float: left; width: 100%; }
.trace-code li + li { margin-top: 5px; }
.trace-code li.selected { background: var(--trace-selected-background); margin-top: 2px; }
.trace-code li code { color: var(--base-6); white-space: nowrap; }
.trace-code li code { color: var(--base-6); white-space: pre; }

.trace-as-text .stacktrace { line-height: 1.8; margin: 0 0 15px; white-space: pre-wrap; }

Expand Down

0 comments on commit c25da5c

Please sign in to comment.