Bluefish is a pretty good editor for programmers and web designers which supports syntax highlighting for many languages – PHP included. While I do like it, there is one little problem when it comes to highlighting PHP code that contains HEREDOC syntax.
I Googled around but failed to find a working solution so I decided to mess around with regular expressions to add my fix. Guess what? I got it working. Here’s how you can add HEREDOC syntax highlighting for PHP In Bluefish.
- In Bluefish, click Edit -> Preferences. Then select the Syntax Highlighting tab
- Select “php” from the filetype dropdown
- Type HEREDOC in “Pattern Name”. Don’t click “Add” yet.
- Choose “Only Start Pattern”
- Type <<<([A-Z]+)\n.*?\n\1; in the “Start Pattern” field
- Type ^PHP Block$ in the “Parentmatch” field
- Type #009900 in the Foreground color field
- Select the “force non-bold weight” and “force non-italic style” radio buttons
- Click “Add”
- Scroll down to the bottom, click HEREDOC and click “Up” until HEREDOC is placed just above “Operators”
- Now, select “Operators” and change its “Start pattern” to [\+\-\*\/\.<>=`!%]+?(?!\?php)
- Click “Apply” then click “OK”
Bluefish should now properly apply syntax highlighting to strings defined the HEREDOC way.