How to syntax-highlight XML in CDATA elements in Vim?
- by Jim Hurne
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.