Skip to content

Code fragments in PHP don't highlight if some lexer options are not set

The PHP lexer ignores everything that is not enclosed in <?php ... ?> tags. When I tried it on a PHP code fragment, I thought the extension is not working. It gave no error message but it didn't highlight the code neither. Then I had the idea to prepend the <?php tag, and it worked. So that is a valid workaround, prepend the <?php tag, highlight the code, delete the tag. I've read up a bit on Pygments and Pymenter and I found out that the pygments lexer has the startinline option that "If given and True the lexer starts highlighting with php code (i.e.: no starting <?php required). The default is False." (from the pygments docs). So either codehihlighter2 could expose lexer options in the GUI or add a "php (fragment)" to the language list.

Edit: don't set it as the default, PHP began as a templating language and sometimes ignoring (not highlighting) the text outside the tags is the desired behavior.

Edited by Tibor Szabo