How to Add HEREDOC Syntax Highlighting for PHP in Bluefish

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.

  1. In Bluefish, click Edit -> Preferences.  Then select the Syntax Highlighting tab
  2. Select “php” from the filetype dropdown
  3. Type HEREDOC in “Pattern Name”.  Don’t click “Add” yet.
  4. Choose “Only Start Pattern”
  5. Type <<<([A-Z]+)\n.*?\n\1; in the “Start Pattern” field
  6. Type ^PHP Block$ in the “Parentmatch” field
  7. Type #009900 in the Foreground color field
  8. Select the “force non-bold weight” and “force non-italic style” radio buttons
  9. Click “Add”
  10. Scroll down to the bottom, click HEREDOC and click “Up” until HEREDOC is placed just above “Operators”
  11. Now, select “Operators” and change its “Start pattern” to [\+\-\*\/\.<>=`!%]+?(?!\?php)
  12. Click “Apply” then click “OK”

Bluefish should now properly apply syntax highlighting to strings defined the HEREDOC way.