Drop \n when highlighting#79
Conversation
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
|
For an easier understanding, it would be nice if you could provide examples. How exactly does it interfere? Why do we now need to remove the |
|
To properly include the original indentation of stuff output of formatting is insufficient, because the selector doesn't match. However putting Without the newlines: |
|
Honestly, we should probably stop using We could fix the function within php-src because we technically are allowed to by the PHP documentation:
I think it would be the best fix, but we would need to wait for the next minor PHP release and then upgrade the environment for php.net. The fix would be easy:
No more breaking HTML standard, no more adjustments of the output, and no more CSS styles on php.net. For the time being, I guess we could accept your PR. |
|
|
||
| if ($role == 'php') { | ||
| try { | ||
| return str_replace(' ', ' ', highlight_string($text, 1)); |
There was a problem hiding this comment.
str_replace() can also take an array of values to replace and an array of what those values should be, why not just use that?
But the issue seems to be more that \n tags before and after are being converted to <br> so wouldn't it make more sense to just ltrim() new lines of the $text variable?
There was a problem hiding this comment.
str_replace()can also take an array of values to replace and an array of what those values should be, why not just use that?
see #79 (comment)
But the issue seems to be more that \n tags before and after are being converted to
so wouldn't it make more sense to just ltrim() new lines of the $text variable?
This wouldn't work, because the extra newlines are inserted by highlight_string(), namely here:
and here:
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] <php/php-src#11913> [2] <php#79>
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] <php/php-src#11913> [2] <#79>


In a second step the CSS will need to be adjusted.
Actual newlines will be replaced by
<br />during highlighting and the\nin the boilerplate conflicts withwhite-space: pre;.see php/doc-en#2648