1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
|
" Vim syntax file
" Language: HTML
" Maintainer: Doug Kearns <dougkearns@gmail.com>
" Previous Maintainers: Jorge Maldonado Ventura <jorgesumle@freakspot.net>
" Claudio Fleiner <claudio@fleiner.com>
" Last Change: 2023 Nov 28
" See :help html.vim for some comments and a description of the options
" quit when a syntax file was already loaded
if !exists("main_syntax")
if exists("b:current_syntax")
finish
endif
let main_syntax = 'html'
endif
let s:cpo_save = &cpo
set cpo&vim
syntax spell toplevel
syn include @htmlXml syntax/xml.vim
unlet b:current_syntax
syn case ignore
" mark illegal characters
syn match htmlError "[<>&]"
" tags
syn region htmlString contained start=+"+ end=+"+ contains=htmlSpecialChar,javaScriptExpression,@htmlPreproc
syn region htmlString contained start=+'+ end=+'+ contains=htmlSpecialChar,javaScriptExpression,@htmlPreproc
syn match htmlValue contained "=[\t ]*[^'" \t>][^ \t>]*"hs=s+1 contains=javaScriptExpression,@htmlPreproc
syn region htmlEndTag start=+</+ end=+>+ contains=htmlTagN,htmlTagError
syn region htmlTag start=+<[^/]+ end=+>+ fold contains=htmlTagN,htmlString,htmlArg,htmlValue,htmlTagError,htmlEvent,htmlCssDefinition,@htmlPreproc,@htmlArgCluster
syn match htmlTagN contained +<\s*[-a-zA-Z0-9]\++hs=s+1 contains=htmlTagName,htmlSpecialTagName,@htmlTagNameCluster
syn match htmlTagN contained +</\s*[-a-zA-Z0-9]\++hs=s+2 contains=htmlTagName,htmlSpecialTagName,@htmlTagNameCluster
syn match htmlTagError contained "[^>]<"ms=s+1
" tag names
syn keyword htmlTagName contained address applet area a base basefont
syn keyword htmlTagName contained big blockquote br caption center
syn keyword htmlTagName contained cite code dd dfn dir div dl dt font
syn keyword htmlTagName contained form hr html img
syn keyword htmlTagName contained input isindex kbd li link map menu
syn keyword htmlTagName contained meta ol option param pre p samp span
syn keyword htmlTagName contained select small strike sub sup
syn keyword htmlTagName contained table td textarea th tr tt ul var xmp
syn match htmlTagName contained "\<\%(b\|i\|u\|h[1-6]\|em\|strong\|head\|body\|title\)\>"
" new html 4.0 tags
syn keyword htmlTagName contained abbr acronym bdo button col colgroup
syn keyword htmlTagName contained del fieldset iframe ins label legend
syn keyword htmlTagName contained object optgroup q s tbody tfoot thead
" new html 5 tags
syn keyword htmlTagName contained article aside audio bdi canvas data
syn keyword htmlTagName contained datalist details dialog embed figcaption
syn keyword htmlTagName contained figure footer header hgroup keygen main
syn keyword htmlTagName contained mark menuitem meter nav output picture
syn keyword htmlTagName contained progress rb rp rt rtc ruby search section
syn keyword htmlTagName contained slot source summary template time track
syn keyword htmlTagName contained video wbr
" svg and math tags
syn keyword htmlMathTagName contained math
syn keyword htmlSvgTagName contained svg
syn region htmlMath start="<math>" end="</math>" contains=@htmlXml transparent keepend
syn region htmlSvg start="<svg>" end="</svg>" contains=@htmlXml transparent keepend
syn cluster xmlTagHook add=htmlMathTagName,htmlSvgTagName
" legal arg names
syn keyword htmlArg contained action
syn keyword htmlArg contained align alink alt archive background bgcolor
syn keyword htmlArg contained border bordercolor cellpadding
syn keyword htmlArg contained cellspacing checked class clear code codebase color
syn keyword htmlArg contained cols colspan content coords enctype face
syn keyword htmlArg contained gutter height hspace id
syn keyword htmlArg contained link lowsrc marginheight
syn keyword htmlArg contained marginwidth maxlength method name prompt
syn keyword htmlArg contained rel rev rows rowspan scrolling selected shape
syn keyword htmlArg contained size src start target text type url
syn keyword htmlArg contained usemap ismap valign value vlink vspace width wrap
syn match htmlArg contained "\<\%(http-equiv\|href\|title\)="me=e-1
syn keyword htmlArg contained role
" ARIA attributes {{{1
let s:aria =<< trim END
activedescendant
atomic
autocomplete
braillelabel
brailleroledescription
busy
checked
colcount
colindex
colindextext
colspan
controls
current
describedby
description
details
disabled
errormessage
expanded
flowto
haspopup
hidden
invalid
keyshortcuts
label
labelledby
level
live
modal
multiline
multiselectable
orientation
owns
placeholder
posinset
pressed
readonly
relevant
required
roledescription
rowcount
rowindex
rowindextext
rowspan
selected
setsize
sort
valuemax
valuemin
valuenow
valuetext
END
let s:aria_deprecated =<< trim END
dropeffect
grabbed
END
call extend(s:aria, s:aria_deprecated)
exe 'syn match htmlArg contained "\%#=1\<aria-\%(' .. s:aria->join('\|') .. '\)\>"'
unlet s:aria s:aria_deprecated
" }}}
" Netscape extensions
syn keyword htmlTagName contained frame noframes frameset nobr blink
syn keyword htmlTagName contained layer ilayer nolayer spacer
syn keyword htmlArg contained frameborder noresize pagex pagey above below
syn keyword htmlArg contained left top visibility clip id noshade
syn match htmlArg contained "\<z-index\>"
" Microsoft extensions
syn keyword htmlTagName contained marquee
" html 4.0 arg names
syn match htmlArg contained "\<\%(accept-charset\|label\)\>"
syn keyword htmlArg contained abbr accept accesskey axis char charoff charset
syn keyword htmlArg contained cite classid codetype compact data datetime
syn keyword htmlArg contained declare defer dir disabled for frame
syn keyword htmlArg contained headers hreflang lang language longdesc
syn keyword htmlArg contained multiple nohref nowrap object profile readonly
syn keyword htmlArg contained rules scheme scope span standby style
syn keyword htmlArg contained summary tabindex valuetype version
" html 5 arg names
syn keyword htmlArg contained allow autocapitalize as blocking decoding
syn keyword htmlArg contained enterkeyhint imagesizes imagesrcset inert
syn keyword htmlArg contained integrity is itemid itemprop itemref itemscope
syn keyword htmlArg contained itemtype loading nomodule ping playsinline
syn keyword htmlArg contained referrerpolicy slot allowfullscreen async
syn keyword htmlArg contained autocomplete autofocus autoplay challenge
syn keyword htmlArg contained contenteditable contextmenu controls crossorigin
syn keyword htmlArg contained default dirname download draggable dropzone form
syn keyword htmlArg contained formaction formenctype formmethod formnovalidate
syn keyword htmlArg contained formtarget hidden high icon inputmode keytype
syn keyword htmlArg contained kind list loop low max min minlength muted nonce
syn keyword htmlArg contained novalidate open optimum pattern placeholder
syn keyword htmlArg contained poster preload radiogroup required reversed
syn keyword htmlArg contained sandbox spellcheck sizes srcset srcdoc srclang
syn keyword htmlArg contained step title translate typemustmatch
syn match htmlArg contained "\<data-\h\%(\w\|[-.]\)*\%(\_s*=\)\@="
" special characters
syn match htmlSpecialChar "&#\=[0-9A-Za-z]\{1,8};"
" Comments (the real ones or the old netscape ones)
if exists("html_wrong_comments")
syn region htmlComment start=+<!--+ end=+--\s*>+ contains=@Spell
else
" The HTML 5.2 syntax 8.2.4.41: bogus comment is parser error; browser skips until next >
syn region htmlComment start=+<!+ end=+>+ contains=htmlCommentError keepend
" Idem 8.2.4.42,51: Comment starts with <!-- and ends with -->
" Idem 8.2.4.43,44: Except <!--> and <!---> are parser errors
" Idem 8.2.4.52: dash-dash-bang (--!>) is error ignored by parser, also closes comment
syn region htmlComment matchgroup=htmlComment start=+<!--\%(-\?>\)\@!+ end=+--!\?>+ contains=htmlCommentNested,@htmlPreProc,@Spell keepend
" Idem 8.2.4.49: nested comment is parser error, except <!--> is all right
syn match htmlCommentNested contained "<!-->\@!"
syn match htmlCommentError contained "[^><!]"
endif
syn region htmlComment start=+<!DOCTYPE+ end=+>+ keepend
" server-parsed commands
syn region htmlPreProc start=+<!--#+ end=+-->+ contains=htmlPreStmt,htmlPreError,htmlPreAttr
syn match htmlPreStmt contained "<!--#\%(config\|echo\|exec\|fsize\|flastmod\|include\|printenv\|set\|if\|elif\|else\|endif\|geoguide\)\>"
syn match htmlPreError contained "<!--#\S*"ms=s+4
syn match htmlPreAttr contained "\w\+=[^"]\S\+" contains=htmlPreProcAttrError,htmlPreProcAttrName
syn region htmlPreAttr contained start=+\w\+="+ skip=+\\\\\|\\"+ end=+"+ contains=htmlPreProcAttrName keepend
syn match htmlPreProcAttrError contained "\w\+="he=e-1
syn match htmlPreProcAttrName contained "\%(expr\|errmsg\|sizefmt\|timefmt\|var\|cgi\|cmd\|file\|virtual\|value\)="he=e-1
if !exists("html_no_rendering")
" rendering
syn cluster htmlTop contains=@Spell,htmlTag,htmlEndTag,htmlSpecialChar,htmlPreProc,htmlComment,htmlLink,javaScript,@htmlPreproc
syn region htmlStrike start="<del\>" end="</del\_s*>"me=s-1 contains=@htmlTop
syn region htmlStrike start="<s\>" end="</s\_s*>"me=s-1 contains=@htmlTop
syn region htmlStrike start="<strike\>" end="</strike\_s*>"me=s-1 contains=@htmlTop
syn region htmlBold start="<b\>" end="</b\_s*>"me=s-1 contains=@htmlTop,htmlBoldUnderline,htmlBoldItalic
syn region htmlBold start="<strong\>" end="</strong\_s*>"me=s-1 contains=@htmlTop,htmlBoldUnderline,htmlBoldItalic
syn region htmlBoldUnderline contained start="<u\>" end="</u\_s*>"me=s-1 contains=@htmlTop,htmlBoldUnderlineItalic
syn region htmlBoldItalic contained start="<i\>" end="</i\_s*>"me=s-1 contains=@htmlTop,htmlBoldItalicUnderline
syn region htmlBoldItalic contained start="<em\>" end="</em\_s*>"me=s-1 contains=@htmlTop,htmlBoldItalicUnderline
syn region htmlBoldUnderlineItalic contained start="<i\>" end="</i\_s*>"me=s-1 contains=@htmlTop
syn region htmlBoldUnderlineItalic contained start="<em\>" end="</em\_s*>"me=s-1 contains=@htmlTop
syn region htmlBoldItalicUnderline contained start="<u\>" end="</u\_s*>"me=s-1 contains=@htmlTop,htmlBoldUnderlineItalic
syn region htmlUnderline start="<u\>" end="</u\_s*>"me=s-1 contains=@htmlTop,htmlUnderlineBold,htmlUnderlineItalic
syn region htmlUnderlineBold contained start="<b\>" end="</b\_s*>"me=s-1 contains=@htmlTop,htmlUnderlineBoldItalic
syn region htmlUnderlineBold contained start="<strong\>" end="</strong\_s*>"me=s-1 contains=@htmlTop,htmlUnderlineBoldItalic
syn region htmlUnderlineItalic contained start="<i\>" end="</i\_s*>"me=s-1 contains=@htmlTop,htmlUnderlineItalicBold
syn region htmlUnderlineItalic contained start="<em\>" end="</em\_s*>"me=s-1 contains=@htmlTop,htmlUnderlineItalicBold
syn region htmlUnderlineItalicBold contained start="<b\>" end="</b\_s*>"me=s-1 contains=@htmlTop
syn region htmlUnderlineItalicBold contained start="<strong\>" end="</strong\_s*>"me=s-1 contains=@htmlTop
syn region htmlUnderlineBoldItalic contained start="<i\>" end="</i\_s*>"me=s-1 contains=@htmlTop
syn region htmlUnderlineBoldItalic contained start="<em\>" end="</em\_s*>"me=s-1 contains=@htmlTop
syn region htmlItalic start="<i\>" end="</i\_s*>"me=s-1 contains=@htmlTop,htmlItalicBold,htmlItalicUnderline
syn region htmlItalic start="<em\>" end="</em\_s*>"me=s-1 contains=@htmlTop
syn region htmlItalicBold contained start="<b\>" end="</b\_s*>"me=s-1 contains=@htmlTop,htmlItalicBoldUnderline
syn region htmlItalicBold contained start="<strong\>" end="</strong\_s*>"me=s-1 contains=@htmlTop,htmlItalicBoldUnderline
syn region htmlItalicBoldUnderline contained start="<u\>" end="</u\_s*>"me=s-1 contains=@htmlTop
syn region htmlItalicUnderline contained start="<u\>" end="</u\_s*>"me=s-1 contains=@htmlTop,htmlItalicUnderlineBold
syn region htmlItalicUnderlineBold contained start="<b\>" end="</b\_s*>"me=s-1 contains=@htmlTop
syn region htmlItalicUnderlineBold contained start="<strong\>" end="</strong\_s*>"me=s-1 contains=@htmlTop
syn match htmlLeadingSpace "^\s\+" contained
syn region htmlLink start="<a\>\_[^>]*\<href\>" end="</a\_s*>"me=s-1 contains=@Spell,htmlTag,htmlEndTag,htmlSpecialChar,htmlPreProc,htmlComment,htmlLeadingSpace,javaScript,@htmlPreproc
syn region htmlH1 start="<h1\>" end="</h1\_s*>"me=s-1 contains=@htmlTop
syn region htmlH2 start="<h2\>" end="</h2\_s*>"me=s-1 contains=@htmlTop
syn region htmlH3 start="<h3\>" end="</h3\_s*>"me=s-1 contains=@htmlTop
syn region htmlH4 start="<h4\>" end="</h4\_s*>"me=s-1 contains=@htmlTop
syn region htmlH5 start="<h5\>" end="</h5\_s*>"me=s-1 contains=@htmlTop
syn region htmlH6 start="<h6\>" end="</h6\_s*>"me=s-1 contains=@htmlTop
syn region htmlHead start="<head\>" end="</head\_s*>"me=s-1 end="<body\>"me=s-1 end="<h[1-6]\>"me=s-1 contains=htmlTag,htmlEndTag,htmlSpecialChar,htmlPreProc,htmlComment,htmlLink,htmlTitle,javaScript,cssStyle,@htmlPreproc
syn region htmlTitle start="<title\>" end="</title\_s*>"me=s-1 contains=htmlTag,htmlEndTag,htmlSpecialChar,htmlPreProc,htmlComment,javaScript,@htmlPreproc
endif
syn keyword htmlTagName contained noscript
syn keyword htmlSpecialTagName contained script style
if main_syntax != 'java' || exists("java_javascript")
" JAVA SCRIPT
syn include @htmlJavaScript syntax/javascript.vim
unlet b:current_syntax
syn region javaScript start=+<script\>\_[^>]*>+ keepend end=+</script\_[^>]*>+me=s-1 contains=@htmlJavaScript,htmlCssStyleComment,htmlScriptTag,@htmlPreproc
syn region htmlScriptTag contained start=+<script+ end=+>+ fold contains=htmlTagN,htmlString,htmlArg,htmlValue,htmlTagError,htmlEvent
hi def link htmlScriptTag htmlTag
" html events (i.e. arguments that include javascript commands)
if exists("html_extended_events")
syn region htmlEvent contained start=+\<on\a\+\s*=[\t ]*'+ end=+'+ contains=htmlEventSQ
syn region htmlEvent contained start=+\<on\a\+\s*=[\t ]*"+ end=+"+ contains=htmlEventDQ
else
syn region htmlEvent contained start=+\<on\a\+\s*=[\t ]*'+ end=+'+ keepend contains=htmlEventSQ
syn region htmlEvent contained start=+\<on\a\+\s*=[\t ]*"+ end=+"+ keepend contains=htmlEventDQ
endif
syn region htmlEventSQ contained start=+'+ms=s+1 end=+'+me=s-1 contains=@htmlJavaScript
syn region htmlEventDQ contained start=+"+ms=s+1 end=+"+me=s-1 contains=@htmlJavaScript
hi def link htmlEventSQ htmlEvent
hi def link htmlEventDQ htmlEvent
" a javascript expression is used as an arg value
syn region javaScriptExpression contained start=+&{+ keepend end=+};+ contains=@htmlJavaScript,@htmlPreproc
endif
if main_syntax != 'java' || exists("java_vb")
" VB SCRIPT
syn include @htmlVbScript syntax/vb.vim
unlet b:current_syntax
syn region javaScript start=+<script \_[^>]*language *=\_[^>]*vbscript\_[^>]*>+ keepend end=+</script\_[^>]*>+me=s-1 contains=@htmlVbScript,htmlCssStyleComment,htmlScriptTag,@htmlPreproc
endif
syn cluster htmlJavaScript add=@htmlPreproc
if main_syntax != 'java' || exists("java_css")
" embedded style sheets
syn keyword htmlArg contained media
syn include @htmlCss syntax/css.vim
unlet b:current_syntax
syn region cssStyle start=+<style+ keepend end=+</style>+ contains=@htmlCss,htmlTag,htmlEndTag,htmlCssStyleComment,@htmlPreproc
syn match htmlCssStyleComment contained "\%(<!--\|-->\)"
syn region htmlCssDefinition matchgroup=htmlArg start='style="' keepend matchgroup=htmlString end='"' contains=css.*Attr,css.*Prop,cssComment,cssLength,cssColor,cssURL,cssImportant,cssError,cssString,@htmlPreproc
hi def link htmlStyleArg htmlString
endif
if main_syntax == "html"
" synchronizing (does not always work if a comment includes legal
" html tags, but doing it right would mean to always start
" at the first line, which is too slow)
syn sync match htmlHighlight groupthere NONE "<[/a-zA-Z]"
syn sync match htmlHighlight groupthere javaScript "<script"
syn sync match htmlHighlightSkip "^.*['\"].*$"
syn sync minlines=10
endif
" Folding
" Originally by Ingo Karkat and Marcus Zanona
if get(g:, "html_syntax_folding", 0)
syn region htmlFold start="<\z(\<\%(area\|base\|br\|col\|command\|embed\|hr\|img\|input\|keygen\|link\|meta\|param\|source\|track\|wbr\>\)\@![a-z-]\+\>\)\%(\_s*\_[^/]\?>\|\_s\_[^>]*\_[^>/]>\)" end="</\z1\_s*>" fold transparent keepend extend containedin=htmlHead,htmlH\d
" fold comments (the real ones and the old Netscape ones)
if exists("html_wrong_comments")
syn region htmlComment start=+<!--+ end=+--\s*>\%(\n\s*<!--\)\@!+ contains=@Spell fold
endif
endif
" The default highlighting.
hi def link htmlTag Function
hi def link htmlEndTag Identifier
hi def link htmlArg Type
hi def link htmlTagName htmlStatement
hi def link htmlSpecialTagName Exception
hi def link htmlMathTagName htmlTagName
hi def link htmlSvgTagName htmlTagName
hi def link htmlValue String
hi def link htmlSpecialChar Special
if !exists("html_no_rendering")
hi def link htmlH1 Title
hi def link htmlH2 htmlH1
hi def link htmlH3 htmlH2
hi def link htmlH4 htmlH3
hi def link htmlH5 htmlH4
hi def link htmlH6 htmlH5
hi def link htmlHead PreProc
hi def link htmlTitle Title
hi def link htmlBoldItalicUnderline htmlBoldUnderlineItalic
hi def link htmlUnderlineBold htmlBoldUnderline
hi def link htmlUnderlineItalicBold htmlBoldUnderlineItalic
hi def link htmlUnderlineBoldItalic htmlBoldUnderlineItalic
hi def link htmlItalicUnderline htmlUnderlineItalic
hi def link htmlItalicBold htmlBoldItalic
hi def link htmlItalicBoldUnderline htmlBoldUnderlineItalic
hi def link htmlItalicUnderlineBold htmlBoldUnderlineItalic
hi def link htmlLink Underlined
hi def link htmlLeadingSpace None
if !exists("html_my_rendering")
hi def htmlBold term=bold cterm=bold gui=bold
hi def htmlBoldUnderline term=bold,underline cterm=bold,underline gui=bold,underline
hi def htmlBoldItalic term=bold,italic cterm=bold,italic gui=bold,italic
hi def htmlBoldUnderlineItalic term=bold,italic,underline cterm=bold,italic,underline gui=bold,italic,underline
hi def htmlUnderline term=underline cterm=underline gui=underline
hi def htmlUnderlineItalic term=italic,underline cterm=italic,underline gui=italic,underline
hi def htmlItalic term=italic cterm=italic gui=italic
if v:version > 800 || v:version == 800 && has("patch1038")
hi def htmlStrike term=strikethrough cterm=strikethrough gui=strikethrough
else
hi def htmlStrike term=underline cterm=underline gui=underline
endif
endif
endif
hi def link htmlPreStmt PreProc
hi def link htmlPreError Error
hi def link htmlPreProc PreProc
hi def link htmlPreAttr String
hi def link htmlPreProcAttrName PreProc
hi def link htmlPreProcAttrError Error
hi def link htmlString String
hi def link htmlStatement Statement
hi def link htmlComment Comment
hi def link htmlCommentNested htmlError
hi def link htmlCommentError htmlError
hi def link htmlTagError htmlError
hi def link htmlEvent javaScript
hi def link htmlError Error
hi def link javaScript Special
hi def link javaScriptExpression javaScript
hi def link htmlCssStyleComment Comment
hi def link htmlCssDefinition Special
let b:current_syntax = "html"
if main_syntax == 'html'
unlet main_syntax
endif
let &cpo = s:cpo_save
unlet s:cpo_save
" vim: nowrap sw=2 sts=2 ts=8 noet fdm=marker:
|