Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
xml.vim362 linesDownload Raw Back to syntax
1" Vim syntax file2" Language: XML3" Maintainer: Christian Brabandt <cb@256bit.org>4" Repository: https://github.com/chrisbra/vim-xml-ftplugin5" Previous Maintainer: Johannes Zellner <johannes@zellner.org>6" Author: Paul Siegmann <pauls@euronet.nl>7" Last Changed:	Nov 03, 20198" Filenames:	*.xml9" 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 globally13" 20210428 - Improve syntax synchronizing14 15" CONFIGURATION:16"   syntax folding can be turned on by17"18"      let g:xml_syntax_folding = 119"20"   before the syntax file gets loaded (e.g. in ~/.vimrc).21"   This might slow down syntax highlighting significantly,22"   especially for large files.23"24" CREDITS:25"   The original version was derived by Paul Siegmann from26"   Claudio Fleiner's html.vim.27"28" REFERENCES:29"   [1] http://www.w3.org/TR/2000/REC-xml-2000100630"   [2] http://www.w3.org/XML/1998/06/xmlspec-report-19980910.htm31"32"   as <hirauchi@kiwi.ne.jp> pointed out according to reference [1]33"34"   2.3 Common Syntactic Constructs35"   [4]    NameChar    ::=    Letter | Digit | '.' | '-' | '_' | ':' | CombiningChar | Extender36"   [5]    Name        ::=    (Letter | '_' | ':') (NameChar)*37"38" NOTE:39"   1) empty tag delimiters "/>" inside attribute values (strings)40"      confuse syntax highlighting.41"   2) for large files, folding can be pretty slow, especially when42"      loading a file the first time and viewoptions contains 'folds'43"      so that folds of previous sessions are applied.44"      Don't use 'foldmethod=syntax' in this case.45 46 47" Quit when a syntax file was already loaded48if exists("b:current_syntax")49    finish50endif51 52let s:xml_cpo_save = &cpo53set cpo&vim54 55syn case match56 57" Allow spell checking in tag values,58" there is no syntax region for that,59" so enable spell checking in top-level elements60" <tag>This text is spell checked</tag>61syn spell toplevel62 63" mark illegal characters64syn match xmlError "[<&]"65 66" strings (inside tags) aka VALUES67"68" EXAMPLE:69"70" <tag foo.attribute = "value">71"                      ^^^^^^^72syn region  xmlString contained start=+"+ end=+"+ contains=xmlEntity,@Spell display73syn region  xmlString contained start=+'+ end=+'+ contains=xmlEntity,@Spell display74 75 76" punctuation (within attributes) e.g. <tag xml:foo.attribute ...>77"                                              ^   ^78" syn match   xmlAttribPunct +[-:._]+ contained display79syn match   xmlAttribPunct +[:.]+ contained display80 81" no highlighting for xmlEqual (xmlEqual has no highlighting group)82syn match   xmlEqual +=+ display83 84 85" attribute, everything before the '='86"87" PROVIDES: @xmlAttribHook88"89" EXAMPLE:90"91" <tag foo.attribute = "value">92"      ^^^^^^^^^^^^^93"94syn match   xmlAttrib95    \ +[-'"<]\@1<!\<[a-zA-Z:_][-.0-9a-zA-Z:_]*\>\%(['"]\@!\|$\)+96    \ contained97    \ contains=xmlAttribPunct,@xmlAttribHook98    \ display99 100 101" namespace spec102"103" PROVIDES: @xmlNamespaceHook104"105" EXAMPLE:106"107" <xsl:for-each select = "lola">108"  ^^^109"110if exists("g:xml_namespace_transparent")111syn match   xmlNamespace112    \ +\(<\|</\)\@2<=[^ /!?<>"':]\+[:]\@=+113    \ contained114    \ contains=@xmlNamespaceHook115    \ transparent116    \ display117else118syn match   xmlNamespace119    \ +\(<\|</\)\@2<=[^ /!?<>"':]\+[:]\@=+120    \ contained121    \ contains=@xmlNamespaceHook122    \ display123endif124 125 126" tag name127"128" PROVIDES: @xmlTagHook129"130" EXAMPLE:131"132" <tag foo.attribute = "value">133"  ^^^134"135syn match   xmlTagName136    \ +\%(<\|</\)\@2<=[^ /!?<>"']\++137    \ contained138    \ contains=xmlNamespace,xmlAttribPunct,@xmlTagHook139    \ display140 141 142if exists('g:xml_syntax_folding')143 144    " start tag145    " use matchgroup=xmlTag to skip over the leading '<'146    "147    " PROVIDES: @xmlStartTagHook148    "149    " EXAMPLE:150    "151    " <tag id="whoops">152    " s^^^^^^^^^^^^^^^e153    "154    syn region   xmlTag155	\ matchgroup=xmlTag start=+<[^ /!?<>"']\@=+156	\ matchgroup=xmlTag end=+>+157	\ contained158	\ contains=xmlError,xmlTagName,xmlAttrib,xmlEqual,xmlString,@xmlStartTagHook159 160 161    " highlight the end tag162    "163    " PROVIDES: @xmlTagHook164    " (should we provide a separate @xmlEndTagHook ?)165    "166    " EXAMPLE:167    "168    " </tag>169    " ^^^^^^170    "171    syn region   xmlEndTag172	\ matchgroup=xmlTag start=+</[^ /!?<>"']\@=+173	\ matchgroup=xmlTag end=+>+174	\ contained175	\ contains=xmlTagName,xmlNamespace,xmlAttribPunct,@xmlTagHook176 177    " tag elements with syntax-folding.178    " NOTE: NO HIGHLIGHTING -- highlighting is done by contained elements179    "180    " PROVIDES: @xmlRegionHook181    "182    " EXAMPLE:183    "184    " <tag id="whoops">185    "   <!-- comment -->186    "   <another.tag></another.tag>187    "   <empty.tag/>188    "   some data189    " </tag>190    "191    syn region   xmlRegion192	\ start=+<\z([^ /!?<>"']\+\)+193	\ skip=+<!--\_.\{-}-->+194	\ end=+</\z1\_\s\{-}>+195	\ end=+/>+196	\ fold197	\ contains=xmlTag,xmlEndTag,xmlCdata,xmlRegion,xmlComment,xmlEntity,xmlProcessing,@xmlRegionHook,@Spell198	\ keepend199	\ extend200 201else202 203    " no syntax folding:204    " - contained attribute removed205    " - xmlRegion not defined206    "207    syn region   xmlTag208	\ matchgroup=xmlTag start=+<[^ /!?<>"']\@=+209	\ matchgroup=xmlTag end=+>+210	\ contains=xmlError,xmlTagName,xmlAttrib,xmlEqual,xmlString,@xmlStartTagHook211 212    syn region   xmlEndTag213	\ matchgroup=xmlTag start=+</[^ /!?<>"']\@=+214	\ matchgroup=xmlTag end=+>+215	\ contains=xmlTagName,xmlNamespace,xmlAttribPunct,@xmlTagHook216 217endif218 219 220" &entities; compare with dtd221syn match   xmlEntity                 "&[^; \t]*;" contains=xmlEntityPunct222syn match   xmlEntityPunct  contained "[&.;]"223 224if exists('g:xml_syntax_folding')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.228    syn region  xmlComment229	\ start=+<!+230	\ end=+>+231	\ contains=xmlCommentStart,xmlCommentError232	\ extend233	\ fold234 235else236 237    " no syntax folding:238    " - fold attribute removed239    "240    syn region  xmlComment241	\ start=+<!+242	\ end=+>+243	\ contains=xmlCommentStart,xmlCommentError244	\ extend245 246endif247 248syn match xmlCommentStart   contained "<!" nextgroup=xmlCommentPart249syn keyword xmlTodo         contained TODO FIXME XXX250syn match   xmlCommentError contained "[^><!]"251syn region  xmlCommentPart252    \ start=+--+253    \ end=+--+254    \ contained255    \ contains=xmlTodo,@xmlCommentHook,@Spell256 257 258" CData sections259"260" PROVIDES: @xmlCdataHook261"262syn region    xmlCdata263    \ start=+<!\[CDATA\[+264    \ end=+]]>+265    \ contains=xmlCdataStart,xmlCdataEnd,@xmlCdataHook,@Spell266    \ keepend267    \ extend268 269" using the following line instead leads to corrupt folding at CDATA regions270" syn match    xmlCdata      +<!\[CDATA\[\_.\{-}]]>+  contains=xmlCdataStart,xmlCdataEnd,@xmlCdataHook271syn match    xmlCdataStart +<!\[CDATA\[+  contained contains=xmlCdataCdata272syn keyword  xmlCdataCdata CDATA          contained273syn match    xmlCdataEnd   +]]>+          contained274 275 276" Processing instructions277" This allows "?>" inside strings -- good idea?278syn region  xmlProcessing matchgroup=xmlProcessingDelim start="<?" end="?>" contains=xmlAttrib,xmlEqual,xmlString279 280 281if exists('g:xml_syntax_folding')282 283    " DTD -- we use dtd.vim here284    syn region  xmlDocType matchgroup=xmlDocTypeDecl285	\ start="<!DOCTYPE"he=s+2,rs=s+2 end=">"286	\ fold287	\ contains=xmlDocTypeKeyword,xmlInlineDTD,xmlString288else289 290    " no syntax folding:291    " - fold attribute removed292    "293    syn region  xmlDocType matchgroup=xmlDocTypeDecl294	\ start="<!DOCTYPE"he=s+2,rs=s+2 end=">"295	\ contains=xmlDocTypeKeyword,xmlInlineDTD,xmlString296 297endif298 299syn keyword xmlDocTypeKeyword contained DOCTYPE PUBLIC SYSTEM300syn region  xmlInlineDTD contained matchgroup=xmlDocTypeDecl start="\[" end="]" contains=@xmlDTD301syn include @xmlDTD <sfile>:p:h/dtd.vim302unlet b:current_syntax303 304 305" synchronizing306 307syn sync match xmlSyncComment grouphere xmlComment +<!--+308syn sync match xmlSyncComment groupthere NONE +-->+309 310" The following is slow on large documents (and the doctype is optional311" syn sync match xmlSyncDT grouphere  xmlDocType +\_.\(<!DOCTYPE\)\@=+312" syn sync match xmlSyncDT groupthere  NONE       +]>+313 314if exists('g:xml_syntax_folding')315    syn sync match xmlSync grouphere   xmlRegion  +\_.\(<[^ /!?<>"']\+\)\@=+316    " syn sync match xmlSync grouphere  xmlRegion "<[^ /!?<>"']*>"317    syn sync match xmlSync groupthere  xmlRegion  +</[^ /!?<>"']\+>+318endif319 320syn sync minlines=100 maxlines=200321 322 323" The default highlighting.324hi def link xmlTodo		Todo325hi def link xmlTag		Function326hi def link xmlTagName		Function327hi def link xmlEndTag		Identifier328if !exists("g:xml_namespace_transparent")329    hi def link xmlNamespace	Tag330endif331hi def link xmlEntity		Statement332hi def link xmlEntityPunct	Type333 334hi def link xmlAttribPunct	Comment335hi def link xmlAttrib		Type336 337hi def link xmlString		String338hi def link xmlComment		Comment339hi def link xmlCommentStart	xmlComment340hi def link xmlCommentPart	Comment341hi def link xmlCommentError	Error342hi def link xmlError		Error343 344hi def link xmlProcessingDelim	Comment345hi def link xmlProcessing	Type346 347hi def link xmlCdata		String348hi def link xmlCdataCdata	Statement349hi def link xmlCdataStart	Type350hi def link xmlCdataEnd		Type351 352hi def link xmlDocTypeDecl	Function353hi def link xmlDocTypeKeyword	Statement354hi def link xmlInlineDTD	Function355 356let b:current_syntax = "xml"357 358let &cpo = s:xml_cpo_save359unlet s:xml_cpo_save360 361" vim: ts=4362 
codekingpro/portable-devtools · Team Ai