3 " Maintainer: Johannes Zellner <johannes@zellner.org>
4 " Author and previous maintainer:
5 " Paul Siegmann <pauls@euronet.nl>
6 " Last Change: 2009-07-13 21:26:55
8 " $Id: xml.vim,v 1.3 2006/04/11 21:32:00 vimboss Exp $
11 " syntax folding can be turned on by
13 " let g:xml_syntax_folding = 1
15 " before the syntax file gets loaded (e.g. in ~/.vimrc).
16 " This might slow down syntax highlighting significantly,
17 " especially for large files.
20 " The original version was derived by Paul Siegmann from
21 " Claudio Fleiner's html.vim.
24 " [1] http://www.w3.org/TR/2000/REC-xml-20001006
25 " [2] http://www.w3.org/XML/1998/06/xmlspec-report-19980910.htm
27 " as <hirauchi@kiwi.ne.jp> pointed out according to reference [1]
29 " 2.3 Common Syntactic Constructs
30 " [4] NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' | CombiningChar | Extender
31 " [5] Name ::= (Letter | '_' | ':') (NameChar)*
34 " 1) empty tag delimiters "/>" inside attribute values (strings)
35 " confuse syntax highlighting.
36 " 2) for large files, folding can be pretty slow, especially when
37 " loading a file the first time and viewoptions contains 'folds'
38 " so that folds of previous sessions are applied.
39 " Don't use 'foldmethod=syntax' in this case.
42 " Quit when a syntax file was already loaded
43 if exists("b:current_syntax")
47 let s:xml_cpo_save = &cpo
52 " mark illegal characters
53 syn match xmlError "[<&]"
55 " strings (inside tags) aka VALUES
59 " <tag foo.attribute = "value">
61 syn region xmlString contained start=+"+ end=+"+ contains=xmlEntity,@Spell display
62 syn region xmlString contained start=+'+ end=+'+ contains=xmlEntity,@Spell display
65 " punctuation (within attributes) e.g. <tag xml:foo.attribute ...>
67 " syn match xmlAttribPunct +[-:._]+ contained display
68 syn match xmlAttribPunct +[:.]+ contained display
70 " no highlighting for xmlEqual (xmlEqual has no highlighting group)
71 syn match xmlEqual +=+ display
74 " attribute, everything before the '='
76 " PROVIDES: @xmlAttribHook
80 " <tag foo.attribute = "value">
84 \ +[-'"<]\@<!\<[a-zA-Z:_][-.0-9a-zA-Z0-9:_]*\>\(['">]\@!\|$\)+
86 \ contains=xmlAttribPunct,@xmlAttribHook
92 " PROVIDES: @xmlNamespaceHook
96 " <xsl:for-each select = "lola">
99 if exists("g:xml_namespace_transparent")
100 syn match xmlNamespace
101 \ +\(<\|</\)\@<=[^ /!?<>"':]\+[:]\@=+
103 \ contains=@xmlNamespaceHook
107 syn match xmlNamespace
108 \ +\(<\|</\)\@<=[^ /!?<>"':]\+[:]\@=+
110 \ contains=@xmlNamespaceHook
117 " PROVIDES: @xmlTagHook
121 " <tag foo.attribute = "value">
125 \ +[<]\@<=[^ /!?<>"']\++
127 \ contains=xmlNamespace,xmlAttribPunct,@xmlTagHook
131 if exists('g:xml_syntax_folding')
134 " use matchgroup=xmlTag to skip over the leading '<'
136 " PROVIDES: @xmlStartTagHook
144 \ matchgroup=xmlTag start=+<[^ /!?<>"']\@=+
145 \ matchgroup=xmlTag end=+>+
147 \ contains=xmlError,xmlTagName,xmlAttrib,xmlEqual,xmlString,@xmlStartTagHook
150 " highlight the end tag
152 " PROVIDES: @xmlTagHook
153 " (should we provide a separate @xmlEndTagHook ?)
163 \ contains=xmlNamespace,xmlAttribPunct,@xmlTagHook
166 " tag elements with syntax-folding.
167 " NOTE: NO HIGHLIGHTING -- highlighting is done by contained elements
169 " PROVIDES: @xmlRegionHook
175 " <another.tag></another.tag>
181 \ start=+<\z([^ /!?<>"']\+\)+
182 \ skip=+<!--\_.\{-}-->+
183 \ end=+</\z1\_\s\{-}>+
184 \ matchgroup=xmlEndTag end=+/>+
186 \ contains=xmlTag,xmlEndTag,xmlCdata,xmlRegion,xmlComment,xmlEntity,xmlProcessing,@xmlRegionHook,@Spell
193 " - contained attribute removed
194 " - xmlRegion not defined
197 \ matchgroup=xmlTag start=+<[^ /!?<>"']\@=+
198 \ matchgroup=xmlTag end=+>+
199 \ contains=xmlError,xmlTagName,xmlAttrib,xmlEqual,xmlString,@xmlStartTagHook
203 \ contains=xmlNamespace,xmlAttribPunct,@xmlTagHook
208 " &entities; compare with dtd
209 syn match xmlEntity "&[^; \t]*;" contains=xmlEntityPunct
210 syn match xmlEntityPunct contained "[&.;]"
212 if exists('g:xml_syntax_folding')
214 " The real comments (this implements the comments as defined by xml,
215 " but not all xml pages actually conform to it. Errors are flagged.
216 syn region xmlComment
219 \ contains=xmlCommentStart,xmlCommentError
226 " - fold attribute removed
228 syn region xmlComment
231 \ contains=xmlCommentStart,xmlCommentError
236 syn match xmlCommentStart contained "<!" nextgroup=xmlCommentPart
237 syn keyword xmlTodo contained TODO FIXME XXX
238 syn match xmlCommentError contained "[^><!]"
239 syn region xmlCommentPart
243 \ contains=xmlTodo,@xmlCommentHook,@Spell
248 " PROVIDES: @xmlCdataHook
251 \ start=+<!\[CDATA\[+
253 \ contains=xmlCdataStart,xmlCdataEnd,@xmlCdataHook,@Spell
257 " using the following line instead leads to corrupt folding at CDATA regions
258 " syn match xmlCdata +<!\[CDATA\[\_.\{-}]]>+ contains=xmlCdataStart,xmlCdataEnd,@xmlCdataHook
259 syn match xmlCdataStart +<!\[CDATA\[+ contained contains=xmlCdataCdata
260 syn keyword xmlCdataCdata CDATA contained
261 syn match xmlCdataEnd +]]>+ contained
264 " Processing instructions
265 " This allows "?>" inside strings -- good idea?
266 syn region xmlProcessing matchgroup=xmlProcessingDelim start="<?" end="?>" contains=xmlAttrib,xmlEqual,xmlString
269 if exists('g:xml_syntax_folding')
271 " DTD -- we use dtd.vim here
272 syn region xmlDocType matchgroup=xmlDocTypeDecl
273 \ start="<!DOCTYPE"he=s+2,rs=s+2 end=">"
275 \ contains=xmlDocTypeKeyword,xmlInlineDTD,xmlString
279 " - fold attribute removed
281 syn region xmlDocType matchgroup=xmlDocTypeDecl
282 \ start="<!DOCTYPE"he=s+2,rs=s+2 end=">"
283 \ contains=xmlDocTypeKeyword,xmlInlineDTD,xmlString
287 syn keyword xmlDocTypeKeyword contained DOCTYPE PUBLIC SYSTEM
288 syn region xmlInlineDTD contained matchgroup=xmlDocTypeDecl start="\[" end="]" contains=@xmlDTD
289 syn include @xmlDTD <sfile>:p:h/dtd.vim
290 unlet b:current_syntax
294 " TODO !!! to be improved !!!
296 syn sync match xmlSyncDT grouphere xmlDocType +\_.\(<!DOCTYPE\)\@=+
297 " syn sync match xmlSyncDT groupthere NONE +]>+
299 if exists('g:xml_syntax_folding')
300 syn sync match xmlSync grouphere xmlRegion +\_.\(<[^ /!?<>"']\+\)\@=+
301 " syn sync match xmlSync grouphere xmlRegion "<[^ /!?<>"']*>"
302 syn sync match xmlSync groupthere xmlRegion +</[^ /!?<>"']\+>+
305 syn sync minlines=100
308 " The default highlighting.
309 hi def link xmlTodo Todo
310 hi def link xmlTag Function
311 hi def link xmlTagName Function
312 hi def link xmlEndTag Identifier
313 if !exists("g:xml_namespace_transparent")
314 hi def link xmlNamespace Tag
316 hi def link xmlEntity Statement
317 hi def link xmlEntityPunct Type
319 hi def link xmlAttribPunct Comment
320 hi def link xmlAttrib Type
322 hi def link xmlString String
323 hi def link xmlComment Comment
324 hi def link xmlCommentStart xmlComment
325 hi def link xmlCommentPart Comment
326 hi def link xmlCommentError Error
327 hi def link xmlError Error
329 hi def link xmlProcessingDelim Comment
330 hi def link xmlProcessing Type
332 hi def link xmlCdata String
333 hi def link xmlCdataCdata Statement
334 hi def link xmlCdataStart Type
335 hi def link xmlCdataEnd Type
337 hi def link xmlDocTypeDecl Function
338 hi def link xmlDocTypeKeyword Statement
339 hi def link xmlInlineDTD Function
341 let b:current_syntax = "xml"
343 let &cpo = s:xml_cpo_save