This is related to http://stackoverflow.com/questions/3232518/how-to-update-vim-to-color-code-new-html-elements, but I want the syntax highlighter to only highlight the elements if it detects the html5 doctype at the first line of the file. Is there an easy way to do this?
+2
A:
You would add something like this to the top of the html.vim
syntax file:
if getline(1) =~? '<!DOCTYPE html>' let b:html5 = 1 else let b:html5 = 0 endif
And then throughout the syntax file you can use if b:html5
to check if html5 is being used for the current buffer.
if b:html5 " new html 5 tags syn keyword htmlTagName contained video canvas endif
too much php
2010-08-27 03:47:43
This is pretty great. I assume the =~? '' bit would be replaced with either a regex or a string, i.e., =~? '<!doctype html>'?
wilsona
2010-08-27 12:20:48
Yes, sorry the angle brackets made everything disappear.
too much php
2010-08-29 22:50:19