Skip to content

Commit 01d6beb

Browse files
authored
Drop \n when highlighting (#79)
* Drop `\n` when highlighting Actual newlines will be replaced by `<br />` during highlighting and the `\n` in the boilerplate conflicts with `white-space: pre;`. see php/doc-en#2648 * Simplify character replacement for `highlight_string` result
1 parent 619c1c1 commit 01d6beb

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

phpdotnet/phd/Highlighter.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ public function highlight($text, $role, $format)
6363

6464
if ($role == 'php') {
6565
try {
66-
return str_replace('&nbsp;', ' ', highlight_string($text, 1));
66+
return strtr(highlight_string($text, 1), [
67+
'&nbsp;' => ' ',
68+
"\n" => '',
69+
]);
6770
} catch (\ParseException $e) {
6871
v("Parse error while highlighting PHP code: %s\nText: %s", (string) $e, $text, E_USER_WARNING);
6972

0 commit comments

Comments
 (0)