robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
0d0772c937
master
1" Vim syntax file 2" Language: XML 3" Maintainer: Christian Brabandt <cb@256bit.org> 4" Repository: https://github.com/chrisbra/vim-xml-ftplugin 5" Previous Maintainer: Johannes Zellner <johannes@zellner.org> 6" Author: Paul Siegmann <pauls@euronet.nl> 7" Last Changed: 30 Jun 2026 8" Filenames: *.xml 9" Last Change: 10" 20190923 - Fix xmlEndTag to match xmlTag (vim/vim#884) 11" 20190924 - Fix xmlAttribute property (amadeus/vim-xml@d8ce1c946) 12" 20191103 - Enable spell checking globally 13" 20210428 - Improve syntax synchronizing 14" 20260630 - Improve performance 15 16" CONFIGURATION: 17" syntax folding can be turned on by 18" 19" let g:xml_syntax_folding = 1 20" 21" before the syntax file gets loaded (e.g. in ~/.vimrc). 22" This might slow down syntax highlighting significantly, 23" especially for large files. 24" 25" CREDITS: 26" The original version was derived by Paul Siegmann from 27" Claudio Fleiner's html.vim. 28" 29" REFERENCES: 30" [1] http://www.w3.org/TR/2000/REC-xml-20001006 31" [2] http://www.w3.org/XML/1998/06/xmlspec-report-19980910.htm 32" 33" as <hirauchi@kiwi.ne.jp> pointed out according to reference [1] 34" 35" 2.3 Common Syntactic Constructs 36" [4] NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' | CombiningChar | Extender 37" [5] Name ::= (Letter | '_' | ':') (NameChar)* 38" 39" NOTE: 40" 1) empty tag delimiters "/>" inside attribute values (strings) 41" confuse syntax highlighting. 42" 2) for large files, folding can be pretty slow, especially when 43" loading a file the first time and viewoptions contains 'folds' 44" so that folds of previous sessions are applied. 45" Don't use 'foldmethod=syntax' in this case. 46 47 48" Quit when a syntax file was already loaded 49if exists ( "b:current_syntax" ) 50finish 51endif 52 53let s: xml_cpo_save = & cpo 54set cpo & vim 55 56syn case match 57 58" Allow spell checking in tag values, 59" there is no syntax region for that, 60" so enable spell checking in top-level elements 61" <tag>This text is spell checked</tag> 62syn spell toplevel 63 64" mark illegal characters 65syn match xmlError "< " 66syn match xmlError "& " 67 68" strings (inside tags) aka VALUES 69" 70" EXAMPLE: 71" 72" <tag foo.attribute = "value"> 73" ^^^^^^^ 74syn region xmlString contained start = +" +end = +" +contains = xmlEntity , @Spell display 75syn region xmlString contained start = +' +end = +' +contains = xmlEntity , @Spell display 76 77 78" punctuation (within attributes) e.g. <tag xml:foo.attribute ...> 79" ^ ^ 80" syn match xmlAttribPunct +[-:._]+ contained display 81syn match xmlAttribPunct +[ :. ] +contained display 82 83" no highlighting for xmlEqual (xmlEqual has no highlighting group) 84syn match xmlEqual += +display 85 86 87" attribute, everything before the '=' 88" 89" PROVIDES: @xmlAttribHook 90" 91" EXAMPLE: 92" 93" <tag foo.attribute = "value"> 94" ^^^^^^^^^^^^^ 95" 96syn match xmlAttrib 97 \ +\%#=1 [ -/!?<>"' ] \@1<!\< [ a-zA-Z:_ ][ -.0-9a-zA-Z:_ ] * \> [ '" ] \@! + 98 \contained 99 \contains = xmlAttribPunct , @xmlAttribHook 100 \display 101 102 103if exists ( "g:xml_namespace_transparent" ) 104command ! -nargs = + XmlTransparent <args> transparent 105else 106command ! -nargs = + XmlTransparent <args> 107endif 108 109" namespace spec 110" 111" PROVIDES: @xmlNamespaceHook 112" 113" EXAMPLE: 114" 115" <xsl:for-each select = "lola"> 116" ^^^ 117" 118XmlTransparent syn match xmlNamespace 119 \ +<[^ /!?<>"':]\+\ze:+lc=1 120 \ contained 121 \ contains=@xmlNamespaceHook 122 \ display 123XmlTransparent syn match xmlNamespace 124 \ +</[^ /!?<>"':]\+\ze:+lc=2 125 \ contained 126 \ contains=@xmlNamespaceHook 127 \ display 128 129delcommand XmlTransparent 130 131 132" tag name 133" 134" PROVIDES: @xmlTagHook 135" 136" EXAMPLE: 137" 138" <tag foo.attribute = "value"> 139" ^^^ 140" 141syn match xmlTagName 142 \ +< [ ^ /!?<>"' ] \+ +lc= 1 143 \contained 144 \contains = xmlNamespace , xmlAttribPunct , @xmlTagHook 145 \display 146syn match xmlTagName 147 \ +</ [ ^ /!?<>"' ] \+ +lc= 2 148 \contained 149 \contains = xmlNamespace , xmlAttribPunct , @xmlTagHook 150 \display 151 152 153if exists ( 'g:xml_syntax_folding' ) 154command ! -nargs = + XmlContained <args> contained 155command ! -nargs = + XmlFold <args> fold 156else 157command ! -nargs = + XmlContained <args> 158command ! -nargs = + XmlFold <args> 159endif 160 161" start tag 162" use matchgroup=xmlTag to skip over the leading '<' 163" 164" PROVIDES: @xmlStartTagHook 165" 166" EXAMPLE: 167" 168" <tag id="whoops"> 169" s^^^^^^^^^^^^^^^e 170" 171XmlContained syn region xmlTag 172 \ matchgroup=xmlTag start=+<\ze[^ /!?<>"']+ 173 \ matchgroup=xmlTag end=+>+ 174 \ contains=xmlError,xmlTagName,xmlAttrib,xmlEqual,xmlString,@xmlStartTagHook 175 176 177" highlight the end tag 178" 179" PROVIDES: @xmlTagHook 180" (should we provide a separate @xmlEndTagHook ?) 181" 182" EXAMPLE: 183" 184" </tag> 185" ^^^^^^ 186" 187XmlContained syn region xmlEndTag 188 \ matchgroup=xmlTag start=+</\ze[^ /!?<>"']+ 189 \ matchgroup=xmlTag end=+>+ 190 \ contains=xmlTagName,xmlNamespace,xmlAttribPunct,@xmlTagHook 191 192delcommand XmlContained 193 194 195if exists ( 'g:xml_syntax_folding' ) 196" tag elements with syntax-folding. 197" NOTE: NO HIGHLIGHTING -- highlighting is done by contained elements 198" 199" PROVIDES: @xmlRegionHook 200" 201" EXAMPLE: 202" 203" <tag id="whoops"> 204" <!-- comment --> 205" <another.tag></another.tag> 206" <empty.tag/> 207" some data 208" </tag> 209" 210syn region xmlRegion 211 \start = +<\z( [ ^ /!?<>"' ] \+\) + 212 \skip = +<!--\_.\{-}--> + 213 \end = +</\z1\_\s\{-}> + 214 \end = +/> + 215 \fold 216 \contains = xmlTag , xmlEndTag , xmlCdata , xmlRegion , xmlComment , xmlEntity , xmlProcessing , @xmlRegionHook , @Spell 217 \keepend 218 \extend 219endif 220 221 222" &entities; compare with dtd 223syn match xmlEntity "& [ ^; \t ] * ; "contains = xmlEntityPunct 224syn match xmlEntityPunct contained "[ &.; ] " 225 226" The real comments (this implements the comments as defined by xml, 227" but not all xml pages actually conform to it. Errors are flagged. 228XmlFold syn region xmlComment 229 \ start=+<!+ 230 \ end=+>+ 231 \ contains=xmlCommentStart,xmlCommentError 232 \ extend 233 234syn match xmlCommentStart contained "<! "nextgroup = xmlCommentPart 235syn keyword xmlTodo contained TODO FIXME XXX 236syn match xmlCommentError contained "[ ^><! ] " 237syn region xmlCommentPart 238 \start = +-- + 239 \end = +-- + 240 \contained 241 \contains = xmlTodo , @xmlCommentHook , @Spell 242 243 244" CData sections 245" 246" PROVIDES: @xmlCdataHook 247" 248syn region xmlCdata 249 \start = +<!\[CDATA\[ + 250 \end = +]]> + 251 \contains = xmlCdataStart , xmlCdataEnd , @xmlCdataHook , @Spell 252 \keepend 253 \extend 254 255" using the following line instead leads to corrupt folding at CDATA regions 256" syn match xmlCdata +<!\[CDATA\[\_.\{-}]]>+ contains=xmlCdataStart,xmlCdataEnd,@xmlCdataHook 257syn match xmlCdataStart +<!\[CDATA\[ +contained contains = xmlCdataCdata 258syn keyword xmlCdataCdata CDATA contained 259syn match xmlCdataEnd +]]> +contained 260 261 262" Processing instructions 263" This allows "?>" inside strings -- good idea? 264syn region xmlProcessing matchgroup = xmlProcessingDelim start = "<? "end = "?> "contains = xmlAttrib , xmlEqual , xmlString 265 266 267" DTD -- we use dtd.vim here 268XmlFold syn region xmlDocType matchgroup=xmlDocTypeDecl 269 \ start="<!DOCTYPE"he=s+2,rs=s+2 end=">" 270 \ contains=xmlDocTypeKeyword,xmlInlineDTD,xmlString 271 272delcommand XmlFold 273 274syn keyword xmlDocTypeKeyword contained DOCTYPE PUBLIC SYSTEM 275syn region xmlInlineDTD contained matchgroup = xmlDocTypeDecl start = "\[ "end = "] "contains = @xmlDTD 276syn include @xmlDTD <sfile>:p:h/dtd.vim 277unlet b: current_syntax 278 279 280" synchronizing 281 282syn syncmatch xmlSyncComment groupherexmlComment +<!--+ 283syn syncmatch xmlSyncComment groupthereNONE +-->+ 284 285" The following is slow on large documents (and the doctype is optional 286" syn sync match xmlSyncDT grouphere xmlDocType +\_.\(<!DOCTYPE\)\@=+ 287" syn sync match xmlSyncDT groupthere NONE +]>+ 288 289if exists ( 'g:xml_syntax_folding' ) 290syn syncmatch xmlSync groupherexmlRegion +\_.\(< [ ^ /!?<>"' ] \+\)\@=+ 291" syn sync match xmlSync grouphere xmlRegion "<[^ /!?<>"']*>" 292syn syncmatch xmlSync grouptherexmlRegion +</ [ ^ /!?<>"' ] \+>+ 293endif 294 295syn sync minlines= 100 maxlines=200 296 297 298" The default highlighting. 299hi def link xmlTodo Todo 300hi def link xmlTag Function 301hi def link xmlTagName Function 302hi def link xmlEndTag Identifier 303if ! exists ( "g:xml_namespace_transparent" ) 304hi def link xmlNamespace Tag 305endif 306hi def link xmlEntity Statement 307hi def link xmlEntityPunct Type 308 309hi def link xmlAttribPunct Comment 310hi def link xmlAttrib Type 311 312hi def link xmlString String 313hi def link xmlComment Comment 314hi def link xmlCommentStart xmlComment 315hi def link xmlCommentPart Comment 316hi def link xmlCommentError Error 317hi def link xmlError Error 318 319hi def link xmlProcessingDelim Comment 320hi def link xmlProcessing Type 321 322hi def link xmlCdata String 323hi def link xmlCdataCdata Statement 324hi def link xmlCdataStart Type 325hi def link xmlCdataEnd Type 326 327hi def link xmlDocTypeDecl Function 328hi def link xmlDocTypeKeyword Statement 329hi def link xmlInlineDTD Function 330 331let b: current_syntax = "xml" 332 333let & cpo = s: xml_cpo_save 334unlet s: xml_cpo_save 335 336" vim: ts=4