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