Fixed PHP code is not highlighted in "Insert code"

CMTV

Well-known member
In "Insert code" dialog, PHP code is not highlighted. It only work when prepending the code with <?php. This is super inconvenient.

The highlighting within the post itself works fine with/without <?php.

This happens because of the "wrong" mime in Data\CodeLanguage.php:
PHP:
'php' => [
   'modes' => [
      'htmlmixed',
      'xml',
      'javascript',
      'css',
      'clike',
      'php'
   ],
   'mime' => 'application/x-httpd-php',
   'common' => true
],
It should be 'mime' => 'text/x-php'.

See this also:
 
That's really just down to CodeMirror and how their highlighting works.

There's really only one thing we can do here. Admittedly small, independent PHP snippets are the common case, but in its current form it also supports PHP "mixed mode" in that you can actually get syntax highlighting for PHP, HTML, JavaScript, CSS etc. all in one code editor.

I guess given that mixed PHP and HTML is probably a dying "art" these days we can probably live without that.

Though it does create another inconsistency in that the in-post syntax highlighting supports both fairly seamlessly. We'll just go with the proposed change for now, but if we happen to get complaints the other way that it is missing then we might have to revert this.
 
Thank you for reporting this issue. The issue is now resolved and we are aiming to include that in a future XF release (2.0.12).

Change log:
Remove the "mixed" stuff from CodeMirror's PHP mode so that the opening tag is no longer required.
Any changes made as a result of this issue being resolved may not be rolled out here until later.
 
Yes, but with the condition that the PHP language in the code editor no longer supports highlighting mixed code, i.e. no longer supports CSS, HTML and JavaScript. It will only support highlighting PHP, but with the benefit that it no longer requires a <?php opener.
 
Back
Top Bottom