From 6352085a73685e06308922a776e868096539acb9 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Sat, 5 Oct 2024 02:02:57 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20PHP=20highlighting=20for=20PHP=20?= =?UTF-8?q?=E2=89=A5=208.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PHP 8.3 changed the details of highlighting PHP code[1], basically like we did[2] at roughly the same time. However, both don't work well together, so we avoid that. [1] [2] --- phpdotnet/phd/Highlighter.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/phpdotnet/phd/Highlighter.php b/phpdotnet/phd/Highlighter.php index db82b555..84817728 100644 --- a/phpdotnet/phd/Highlighter.php +++ b/phpdotnet/phd/Highlighter.php @@ -63,10 +63,15 @@ public function highlight($text, $role, $format) if ($role == 'php') { try { - return strtr(highlight_string($text, 1), [ - ' ' => ' ', - "\n" => '', - ]); + $highlight = highlight_string($text, true); + if (PHP_VERSION_ID >= 80300) { + return $highlight; + } else { + return strtr($highlight, [ + ' ' => ' ', + "\n" => '', + ]); + } } catch (\ParseException $e) { v("Parse error while highlighting PHP code: %s\nText: %s", (string) $e, $text, E_USER_WARNING);