3 " Maintainer: Claudio Fleiner <claudio@fleiner.com>
4 " URL: http://www.fleiner.com/vim/syntax/html.vim
5 " Last Change: 2001 May 10
7 " Please check :help html.vim for some comments and a description of the options
9 " For version 5.x: Clear all syntax items
10 " For version 6.x: Quit when a syntax file was already loaded
11 if !exists("main_syntax")
14 elseif exists("b:current_syntax")
17 let main_syntax = 'html'
20 " don't use standard HiLink, it will not work with included syntax files
22 command! -nargs=+ HtmlHiLink hi link <args>
24 command! -nargs=+ HtmlHiLink hi def link <args>
30 " mark illegal characters
31 syn match htmlError "[<>&]"
35 syn region htmlString contained start=+"+ end=+"+ contains=htmlSpecialChar,javaScriptExpression,@htmlPreproc
36 syn region htmlString contained start=+'+ end=+'+ contains=htmlSpecialChar,javaScriptExpression,@htmlPreproc
37 syn match htmlValue contained "=[\t ]*[^'" \t>][^ \t>]*"hs=s+1 contains=javaScriptExpression,@htmlPreproc
38 syn region htmlEndTag start=+</+ end=+>+ contains=htmlTagN,htmlTagError
39 syn region htmlTag start=+<[^/]+ end=+>+ contains=htmlTagN,htmlString,htmlArg,htmlValue,htmlTagError,htmlEvent,htmlCssDefinition,@htmlPreproc,@htmlArgCluster
40 syn match htmlTagN contained +<\s*[-a-zA-Z0-9]\++hs=s+1 contains=htmlTagName,htmlSpecialTagName,@htmlTagNameCluster
41 syn match htmlTagN contained +</\s*[-a-zA-Z0-9]\++hs=s+2 contains=htmlTagName,htmlSpecialTagName,@htmlTagNameCluster
42 syn match htmlTagError contained "[^>]<"ms=s+1
46 syn keyword htmlTagName contained address applet area a base basefont
47 syn keyword htmlTagName contained big blockquote br caption center
48 syn keyword htmlTagName contained cite code dd dfn dir div dl dt font
49 syn keyword htmlTagName contained form hr html img
50 syn keyword htmlTagName contained input isindex kbd li link map menu
51 syn keyword htmlTagName contained meta ol option param pre p samp span
52 syn keyword htmlTagName contained select small strike sub sup
53 syn keyword htmlTagName contained table td textarea th tr tt ul var xmp
54 syn match htmlTagName contained "\<\(b\|i\|u\|h[1-6]\|em\|strong\|head\|body\|title\)\>"
57 syn keyword htmlTagName contained abbr acronym bdo button col label
58 syn keyword htmlTagName contained colgroup del fieldset iframe ins legend
59 syn keyword htmlTagName contained object optgroup q s tbody tfoot thead
62 syn keyword htmlArg contained action
63 syn keyword htmlArg contained align alink alt archive background bgcolor
64 syn keyword htmlArg contained border bordercolor cellpadding
65 syn keyword htmlArg contained cellspacing checked class clear code codebase color
66 syn keyword htmlArg contained cols colspan content coords enctype face
67 syn keyword htmlArg contained gutter height hspace id
68 syn keyword htmlArg contained link lowsrc marginheight
69 syn keyword htmlArg contained marginwidth maxlength method name prompt
70 syn keyword htmlArg contained rel rev rows rowspan scrolling selected shape
71 syn keyword htmlArg contained size src start target text type url
72 syn keyword htmlArg contained usemap ismap valign value vlink vspace width wrap
73 syn match htmlArg contained "\<\(http-equiv\|href\|title\)="me=e-1
76 syn keyword htmlTagName contained frame noframes frameset nobr blink
77 syn keyword htmlTagName contained layer ilayer nolayer spacer
78 syn keyword htmlArg contained frameborder noresize pagex pagey above below
79 syn keyword htmlArg contained left top visibility clip id noshade
80 syn match htmlArg contained "\<z-index\>"
82 " Microsoft extensions
83 syn keyword htmlTagName contained marquee
86 syn match htmlArg contained "\<\(accept-charset\|label\)\>"
87 syn keyword htmlArg contained abbr accept accesskey axis char charoff charset
88 syn keyword htmlArg contained cite classid codetype compact data datetime
89 syn keyword htmlArg contained declare defer dir disabled for frame
90 syn keyword htmlArg contained headers hreflang lang language longdesc
91 syn keyword htmlArg contained multiple nohref nowrap object profile readonly
92 syn keyword htmlArg contained rules scheme scope span standby style
93 syn keyword htmlArg contained summary tabindex valuetype version
96 syn match htmlSpecialChar "&#\=[0-9A-Za-z]\{1,8};"
98 " Comments (the real ones or the old netscape ones)
99 if exists("html_wrong_comments")
100 syn region htmlComment start=+<!--+ end=+--\s*>+
102 syn region htmlComment start=+<!+ end=+>+ contains=htmlCommentPart,htmlCommentError
103 syn match htmlCommentError contained "[^><!]"
104 syn region htmlCommentPart contained start=+--+ end=+--\s*+ contains=@htmlPreProc
106 syn region htmlComment start=+<!DOCTYPE+ keepend end=+>+
108 " server-parsed commands
109 syn region htmlPreProc start=+<!--#+ end=+-->+ contains=htmlPreStmt,htmlPreError,htmlPreAttr
110 syn match htmlPreStmt contained "<!--#\(config\|echo\|exec\|fsize\|flastmod\|include\|printenv\|set\|if\|elif\|else\|endif\|geoguide\)\>"
111 syn match htmlPreError contained "<!--#\S*"ms=s+4
112 syn match htmlPreAttr contained "\w\+=[^"]\S\+" contains=htmlPreProcAttrError,htmlPreProcAttrName
113 syn region htmlPreAttr contained start=+\w\+="+ skip=+\\\\\|\\"+ end=+"+ contains=htmlPreProcAttrName keepend
114 syn match htmlPreProcAttrError contained "\w\+="he=e-1
115 syn match htmlPreProcAttrName contained "\(expr\|errmsg\|sizefmt\|timefmt\|var\|cgi\|cmd\|file\|virtual\|value\)="he=e-1
117 if !exists("html_no_rendering")
119 syn cluster htmlTop contains=@Spell,htmlTag,htmlEndTag,htmlSpecialChar,htmlPreProc,htmlComment,htmlLink,javaScript,@htmlPreproc
121 syn region htmlBold start="<b\>" end="</b>"me=e-4 contains=@htmlTop,htmlBoldUnderline,htmlBoldItalic
122 syn region htmlBold start="<strong\>" end="</strong>"me=e-9 contains=@htmlTop,htmlBoldUnderline,htmlBoldItalic
123 syn region htmlBoldUnderline contained start="<u\>" end="</u>"me=e-4 contains=@htmlTop,htmlBoldUnderlineItalic
124 syn region htmlBoldItalic contained start="<i\>" end="</i>"me=e-4 contains=@htmlTop,htmlBoldItalicUnderline
125 syn region htmlBoldItalic contained start="<em\>" end="</em>"me=e-5 contains=@htmlTop,htmlBoldItalicUnderline
126 syn region htmlBoldUnderlineItalic contained start="<i\>" end="</i>"me=e-4 contains=@htmlTop
127 syn region htmlBoldUnderlineItalic contained start="<em\>" end="</em>"me=e-5 contains=@htmlTop
128 syn region htmlBoldItalicUnderline contained start="<u\>" end="</u>"me=e-4 contains=@htmlTop,htmlBoldUnderlineItalic
130 syn region htmlUnderline start="<u\>" end="</u>"me=e-4 contains=@htmlTop,htmlUnderlineBold,htmlUnderlineItalic
131 syn region htmlUnderlineBold contained start="<b\>" end="</b>"me=e-4 contains=@htmlTop,htmlUnderlineBoldItalic
132 syn region htmlUnderlineBold contained start="<strong\>" end="</strong>"me=e-9 contains=@htmlTop,htmlUnderlineBoldItalic
133 syn region htmlUnderlineItalic contained start="<i\>" end="</i>"me=e-4 contains=@htmlTop,htmUnderlineItalicBold
134 syn region htmlUnderlineItalic contained start="<em\>" end="</em>"me=e-5 contains=@htmlTop,htmUnderlineItalicBold
135 syn region htmlUnderlineItalicBold contained start="<b\>" end="</b>"me=e-4 contains=@htmlTop
136 syn region htmlUnderlineItalicBold contained start="<strong\>" end="</strong>"me=e-9 contains=@htmlTop
137 syn region htmlUnderlineBoldItalic contained start="<i\>" end="</i>"me=e-4 contains=@htmlTop
138 syn region htmlUnderlineBoldItalic contained start="<em\>" end="</em>"me=e-5 contains=@htmlTop
140 syn region htmlItalic start="<i\>" end="</i>"me=e-4 contains=@htmlTop,htmlItalicBold,htmlItalicUnderline
141 syn region htmlItalic start="<em\>" end="</em>"me=e-5 contains=@htmlTop
142 syn region htmlItalicBold contained start="<b\>" end="</b>"me=e-4 contains=@htmlTop,htmlItalicBoldUnderline
143 syn region htmlItalicBold contained start="<strong\>" end="</strong>"me=e-9 contains=@htmlTop,htmlItalicBoldUnderline
144 syn region htmlItalicBoldUnderline contained start="<u\>" end="</u>"me=e-4 contains=@htmlTop
145 syn region htmlItalicUnderline contained start="<u\>" end="</u>"me=e-4 contains=@htmlTop,htmlItalicUnderlineBold
146 syn region htmlItalicUnderlineBold contained start="<b\>" end="</b>"me=e-4 contains=@htmlTop
147 syn region htmlItalicUnderlineBold contained start="<strong\>" end="</strong>"me=e-9 contains=@htmlTop
149 syn region htmlLink start="<a\>[^>]*href\>" end="</a>"me=e-4 contains=@Spell,htmlTag,htmlEndTag,htmlSpecialChar,htmlPreProc,htmlComment,javaScript,@htmlPreproc
150 syn region htmlH1 start="<h1\>" end="</h1>"me=e-5 contains=@htmlTop
151 syn region htmlH2 start="<h2\>" end="</h2>"me=e-5 contains=@htmlTop
152 syn region htmlH3 start="<h3\>" end="</h3>"me=e-5 contains=@htmlTop
153 syn region htmlH4 start="<h4\>" end="</h4>"me=e-5 contains=@htmlTop
154 syn region htmlH5 start="<h5\>" end="</h5>"me=e-5 contains=@htmlTop
155 syn region htmlH6 start="<h6\>" end="</h6>"me=e-5 contains=@htmlTop
156 syn region htmlHead start="<head\>" end="</head>"me=e-7 end="<body\>"me=e-5 end="<h[1-6]\>"me=e-3 contains=htmlTag,htmlEndTag,htmlSpecialChar,htmlPreProc,htmlComment,htmlLink,htmlTitle,javaScript,cssStyle,@htmlPreproc
157 syn region htmlTitle start="<title\>" end="</title>"me=e-8 contains=htmlTag,htmlEndTag,htmlSpecialChar,htmlPreProc,htmlComment,javaScript,@htmlPreproc
160 syn keyword htmlTagName contained noscript
161 syn keyword htmlSpecialTagName contained script style
162 if main_syntax != 'java' || exists("java_javascript")
164 syn include @htmlJavaScript <sfile>:p:h/javascript.vim
165 unlet b:current_syntax
166 syn region javaScript start=+<script[^>]*>+ keepend end=+</script>+me=s-1 contains=@htmlJavaScript,htmlCssStyleComment,htmlScriptTag,@htmlPreproc
167 syn region htmlScriptTag contained start=+<script+ end=+>+ contains=htmlTagN,htmlString,htmlArg,htmlValue,htmlTagError,htmlEvent
168 HtmlHiLink htmlScriptTag htmlTag
170 " html events (i.e. arguments that include javascript commands)
171 if exists("html_extended_events")
172 syn region htmlEvent contained start=+on\a\+\s*=[\t ]*'+ end=+'+ contains=htmlEventSQ
173 syn region htmlEvent contained start=+on\a\+\s*=[\t ]*"+ end=+"+ contains=htmlEventDQ
175 syn region htmlEvent contained start=+on\a\+\s*=[\t ]*'+ end=+'+ keepend contains=htmlEventSQ
176 syn region htmlEvent contained start=+on\a\+\s*=[\t ]*"+ end=+"+ keepend contains=htmlEventDQ
178 syn region htmlEventSQ contained start=+'+ms=s+1 end=+'+me=s-1 contains=@htmlJavaScript
179 syn region htmlEventDQ contained start=+"+ms=s+1 end=+"+me=s-1 contains=@htmlJavaScript
180 HtmlHiLink htmlEventSQ htmlEvent
181 HtmlHiLink htmlEventDQ htmlEvent
183 " a javascript expression is used as an arg value
184 syn region javaScriptExpression contained start=+&{+ keepend end=+};+ contains=@htmlJavaScript,@htmlPreproc
187 if main_syntax != 'java' || exists("java_vb")
189 syn include @htmlVbScript <sfile>:p:h/vb.vim
190 unlet b:current_syntax
191 syn region javaScript start=+<script [^>]*language *=[^>]*vbscript[^>]*>+ keepend end=+</script>+me=s-1 contains=@htmlVbScript,htmlCssStyleComment,htmlScriptTag,@htmlPreproc
194 syn cluster htmlJavaScript add=@htmlPreproc
196 if main_syntax != 'java' || exists("java_css")
197 " embedded style sheets
198 syn keyword htmlArg contained media
199 syn include @htmlCss <sfile>:p:h/css.vim
200 unlet b:current_syntax
201 syn region cssStyle start=+<style+ keepend end=+</style>+ contains=@htmlCss,htmlTag,htmlEndTag,htmlCssStyleComment,@htmlPreproc
202 syn match htmlCssStyleComment contained "\(<!--\|-->\)"
203 syn region htmlCssDefinition matchgroup=htmlArg start='style="' keepend matchgroup=htmlString end='"' contains=css.*Attr,css.*Properties,cssComment,cssLength,cssColor,cssURL,cssImportant,cssError,cssString,@htmlPreproc
204 HtmlHiLink htmlStyleArg htmlString
207 if main_syntax == "html"
208 " synchronizing (does not always work if a comment includes legal
209 " html tags, but doing it right would mean to always start
210 " at the first line, which is too slow)
211 syn sync match htmlHighlight groupthere NONE "<[/a-zA-Z]"
212 syn sync match htmlHighlight groupthere javaScript "<script"
213 syn sync match htmlHighlightSkip "^.*['\"].*$"
217 " The default highlighting.
218 if version >= 508 || !exists("did_html_syn_inits")
220 let did_html_syn_inits = 1
222 HtmlHiLink htmlTag Function
223 HtmlHiLink htmlEndTag Identifier
224 HtmlHiLink htmlArg Type
225 HtmlHiLink htmlTagName htmlStatement
226 HtmlHiLink htmlSpecialTagName Exception
227 HtmlHiLink htmlValue String
228 HtmlHiLink htmlSpecialChar Special
230 if !exists("html_no_rendering")
231 HtmlHiLink htmlH1 Title
232 HtmlHiLink htmlH2 htmlH1
233 HtmlHiLink htmlH3 htmlH2
234 HtmlHiLink htmlH4 htmlH3
235 HtmlHiLink htmlH5 htmlH4
236 HtmlHiLink htmlH6 htmlH5
237 HtmlHiLink htmlHead PreProc
238 HtmlHiLink htmlTitle Title
239 HtmlHiLink htmlBoldItalicUnderline htmlBoldUnderlineItalic
240 HtmlHiLink htmlUnderlineBold htmlBoldUnderline
241 HtmlHiLink htmlUnderlineItalicBold htmlBoldUnderlineItalic
242 HtmlHiLink htmlUnderlineBoldItalic htmlBoldUnderlineItalic
243 HtmlHiLink htmlItalicUnderline htmlUnderlineItalic
244 HtmlHiLink htmlItalicBold htmlBoldItalic
245 HtmlHiLink htmlItalicBoldUnderline htmlBoldUnderlineItalic
246 HtmlHiLink htmlItalicUnderlineBold htmlBoldUnderlineItalic
247 if !exists("html_my_rendering")
248 if &background == "dark"
249 hi def htmlLink term=underline cterm=underline ctermfg=cyan gui=underline guifg=#80a0ff
251 hi def htmlLink term=underline cterm=underline ctermfg=DarkBlue gui=underline guifg=Blue
253 hi def htmlBold term=bold cterm=bold gui=bold
254 hi def htmlBoldUnderline term=bold,underline cterm=bold,underline gui=bold,underline
255 hi def htmlBoldItalic term=bold,italic cterm=bold,italic gui=bold,italic
256 hi def htmlBoldUnderlineItalic term=bold,italic,underline cterm=bold,italic,underline gui=bold,italic,underline
257 hi def htmlUnderline term=underline cterm=underline gui=underline
258 hi def htmlUnderlineItalic term=italic,underline cterm=italic,underline gui=italic,underline
259 hi def htmlItalic term=italic cterm=italic gui=italic
263 HtmlHiLink htmlPreStmt PreProc
264 HtmlHiLink htmlPreError Error
265 HtmlHiLink htmlPreProc PreProc
266 HtmlHiLink htmlPreAttr String
267 HtmlHiLink htmlPreProcAttrName PreProc
268 HtmlHiLink htmlPreProcAttrError Error
269 HtmlHiLink htmlSpecial Special
270 HtmlHiLink htmlSpecialChar Special
271 HtmlHiLink htmlString String
272 HtmlHiLink htmlStatement Statement
273 HtmlHiLink htmlComment Comment
274 HtmlHiLink htmlCommentPart Comment
275 HtmlHiLink htmlValue String
276 HtmlHiLink htmlCommentError htmlError
277 HtmlHiLink htmlTagError htmlError
278 HtmlHiLink htmlEvent javaScript
279 HtmlHiLink htmlError Error
281 HtmlHiLink javaScript Special
282 HtmlHiLink javaScriptExpression javaScript
283 HtmlHiLink htmlCssStyleComment Comment
284 HtmlHiLink htmlCssDefinition Special
287 delcommand HtmlHiLink
289 let b:current_syntax = "html"
291 if main_syntax == 'html'