Hi Ben, thanks for the clue!

Ben Fritz wrote:
> 
> My first thought would be to try adding a containedin of whatever
> syntax item is currently matching on the CDATA region. 
> 
So, that's good advice. Reading the xml.vim syntax file, there are 'hooks'
provided in various regions for adding syntax groups to an undefined
cluster. For CDATA, we have:

" CData sections
"
" PROVIDES: @xmlCdataHook
"
syn region    xmlCdata
    \ start=+<!\[CDATA\[+
    \ end=+]]>+
    \ contains=xmlCdataStart,xmlCdataEnd,@xmlCdataHook,@Spell
    \ keepend
    \ extend

Now, this unfortunately isn't as easy to use as it looks like it's intended
to be. This doesn't work:
    unlet b:current_syntax
    syn include @CDATA_HTML $VIMRUNTIME/syntax/html.vim
    syn cluster xmlCdataHook a...@cdata_html
because the @CDATA_HTML rules start matching at the "start of the start" and
it's ugly!

So, I have solved it this way, and propose a patch to xml.vim to make this
'hook' work as intended.

I re-define the region xmlCdata using matchgroup, which specifically allows
for different highlighting of the start & end and the contained "text in
between" (:h :syn-region). This gives slightly less attractive highlighting
of the <![CDATA[ marker itself (no way I can find to make the CDATA
different from the punctuation) but allows the code above to work as
intended.

~/.vim/after/syntax/xml.vim
    " Edited region xmlCdata using matchgroup
    syn region    xmlCdata
        \ matchgroup=Special
        \ start=+<!\[CDATA\[+
        \ end=+]]>+
        \ contai...@xmlcdatahook,@Spell
        \ keepend
        \ extend
    " Now load HTML syntax and add to the 'hook'
    unlet b:current_syntax
    syn include @CDATA_HTML $VIMRUNTIME/syntax/html.vim
    syn cluster xmlCdataHook a...@cdata_html

Cheers, al.

On Jun 15, 11:05 am, Allan Kelly <[email protected]> wrote:
> Now, this is where the problems are:
> :syn region CDATA_HTML_region start=+<!\[CDATA\[+ keepend
> end=+\]\]>+me=s-1 contai...@cdata_html
>
> Nothing happens.
>

My first thought would be to try adding a containedin of whatever
syntax item is currently matching on the CDATA region.

If that doesn't work, you may want to see if you're missing anything
from here:

http://vim.wikia.com/wiki/Different_syntax_highlighting_within_regions_of_a_file




-- 
View this message in context: 
http://www.nabble.com/Syntax-includes-tp24038226p24042108.html
Sent from the Vim - General mailing list archive at Nabble.com.


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to