Syntax highlighting problem with .html.erb files in Kate text editor

Recently, I've been trying out the Kate (http://kate-editor.org/) text editor when programming. It's free, lightweight, and seems quite nice. It has most of the features of TextMate (my current favorite), runs on Linux, and is free.

Last weekend I noticed the syntax highlighting for Ruby on Rails view templates (files ending in .html.erb) was all messed up. Matching tags were not marked, functions weren't highlighted, and everything was basically really difficult to read.

After trolling around Kate's configuration files, I think I found the issue. I submitted a bug to the KDE development team, but in the meantime I thought I'd post this for anyone else trying to do RoR work in this editor.
https://bugs.kde.org/show_bug.cgi?id=177158

Kate keeps its syntax highlighting definition files in XML files in /usr/share/kde/apps/katepart/syntax. Each file has an element like this one :

rhtml.xml
  <language name="Ruby/Rails/RHTML" version="1.00" kateversion="2.4" section="Markup" extensions="*.rhtml;*.html.erb" mimetype="" author="Richard Dale" license="LGPL">

The 'extensions' part should mean that my template files get highlighted according to the rules in this XML file. But that wasn't happening. It turns out there's another file...
apache.xml
  <language name="Apache Configuration" section="Configuration" extensions="httpd.conf;httpd2.conf;apache.conf;apache2.conf;.ht*" version="1.0" kateversion="2.0" author="Jan Janssen" license="LGPL">

So apparently apache.xml is applied before rhtml.xml.

Kate saves the syntax style for each file you open, which means this broken association will stick around until you fix it manually. I've removed apache.xml from /usr/share/kde/apps/katepart/syntax entirely, since I'll never use Kate to edit Apache config. This may or may not work for you. To fix files which are currently highlighted incorrectly, try this:

  cd ~/.kde/share/apps/kate/sessions
  ls

You will see a .katesession file for each session you have created. You can edit these by hand. I recommend that Kate not be running while you do this. (It crashed on me a few times when I was manually editing the files, which isn't really a surprise, I suppose.) Find the section for the file which is highlighted incorrrectly, and change all occurrences of 'Apache Configuration' to 'Ruby/Rails/RHTML'. Then save and quit.