How to syntax-highlight XML in CDATA elements in Vim?

Posted by Jim Hurne on Stack Overflow See other posts from Stack Overflow or by Jim Hurne
Published on 2010-04-26T12:22:40Z Indexed on 2010/04/26 13:03 UTC
Read the original article Hit count: 284

Filed under:
|
|

Vim's syntax highlighting for XML/XSL is great, except it turns off all syntax highlighting in CDATA regions. Is there a way to turn on syntax highlighting on in CDATA regions?

At work, we have a lot of XSL code embedded within other XML documents. It would be great if I could get all of the goodness of XML editing for the embedded XSL code as well without having to temporarily remove the CDATA tags, or copy the CDATA content into a temporary file.

Example:

<root>
  <someTag><![CDATA[
      <xsl:template match="/">
          <!-- XSL content here -->
      </xsl:template>
   ]]>
  </someTag>
</root>

Note that the name of the tag (in the example, someTag) containing the content could be anything.

We also sometimes embed Javascript inside CDATA regions as well, and again, it would be nice to turn on Javascript syntax highlighting for those regions. Again, the tag the data is embedded in is usually arbitrary and can be anything.

© Stack Overflow or respective owner

Related posts about vim

Related posts about Xml