I have a script that reads an HTML file and replaces occurrences of ~%foo%~ with a value set by Perl. Something like this:
<span class="~%classname%~">~%hi_mom%~</span>
Would produce something like this in the browser:
<span class="classyclass">Hello World</span>
Right so I want to use Vim syntax highlighting to distinguish the occurrences ~%foo%~ in the HTML. By default, the HTML syntax highlighting will make an HTML element's attribute values Magenta and I want the ~%foo%~ portion to be DarkMagenta. I'm on the right track because if I comment out the tokenQuoted lines (or token lines) I get the desired results but with both matches and highlights uncommented the token highlighting overrides the tokenQuoted highlighting.
syntax match token containedin=ALLBUT,htmlString,htmlValue '\~%[^%]\+%\~'
syntax match tokenQuoted containedin=htmlString,htmlValue '\~%[^%]\+%\~'
" tokenQuoted assumes htmlString/htmlValue (:highlight String) is Magenta
highlight token term=none ctermfg=White guifg=White
highlight tokenQuoted term=none ctermfg=DarkMagenta guifg=DarkMagenta
The file I'm working in is sourced after the default html.vim is sourced via
autocmd *.html ~/.vim/syntax/html.vim in .vimrc.