blob: 58f07c98ddb131139936801d93bbb339c875fab3 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
Bram Moolenaar96f45c02019-10-26 19:53:45 +02002" Language: DTD (Document Type Definition for 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: Daniel Amyot <damyot@site.uottawa.ca>
7" Last Changed: Sept 24, 2019
8" Filenames: *.dtd
Bram Moolenaar071d4272004-06-13 20:20:40 +00009"
10" REFERENCES:
11" http://www.w3.org/TR/html40/
12" http://www.w3.org/TR/NOTE-html-970421
13"
14" TODO:
15" - improve synchronizing.
16
Bram Moolenaar8e52a592012-05-18 21:49:28 +020017if exists("b:current_syntax")
18 finish
Bram Moolenaar071d4272004-06-13 20:20:40 +000019endif
Bram Moolenaar8e52a592012-05-18 21:49:28 +020020let s:dtd_cpo_save = &cpo
21set cpo&vim
Bram Moolenaar071d4272004-06-13 20:20:40 +000022
23if !exists("dtd_ignore_case")
24 " I prefer having the case takes into consideration.
25 syn case match
26else
27 syn case ignore
28endif
29
30
31" the following line makes the opening <! and
32" closing > highlighted using 'dtdFunction'.
33"
34" PROVIDES: @dtdTagHook
35"
36syn region dtdTag matchgroup=dtdFunction
37 \ start=+<!+ end=+>+ matchgroup=NONE
38 \ contains=dtdTag,dtdTagName,dtdError,dtdComment,dtdString,dtdAttrType,dtdAttrDef,dtdEnum,dtdParamEntityInst,dtdParamEntityDecl,dtdCard,@dtdTagHook
39
40if !exists("dtd_no_tag_errors")
41 " mark everything as an error which starts with a <!
42 " and is not overridden later. If this is annoying,
43 " it can be switched off by setting the variable
44 " dtd_no_tag_errors.
45 syn region dtdError contained start=+<!+lc=2 end=+>+
46endif
47
Bram Moolenaarfa3b7232021-12-24 13:18:38 +000048" if this is a html like comment highlight also
Bram Moolenaar071d4272004-06-13 20:20:40 +000049" the opening <! and the closing > as Comment.
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000050syn region dtdComment start=+<![ \t]*--+ end=+-->+ contains=dtdTodo,@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +000051
52
53" proper DTD comment
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000054syn region dtdComment contained start=+--+ end=+--+ contains=dtdTodo,@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +000055
56
57" Start tags (keywords). This is contained in dtdFunction.
58" Note that everything not contained here will be marked
59" as error.
60syn match dtdTagName contained +<!\(ATTLIST\|DOCTYPE\|ELEMENT\|ENTITY\|NOTATION\|SHORTREF\|USEMAP\|\[\)+lc=2,hs=s+2
61
62
63" wildcards and operators
64syn match dtdCard contained "|"
65syn match dtdCard contained ","
66" evenutally overridden by dtdEntity
67syn match dtdCard contained "&"
68syn match dtdCard contained "?"
69syn match dtdCard contained "\*"
70syn match dtdCard contained "+"
71
72" ...and finally, special cases.
73syn match dtdCard "ANY"
74syn match dtdCard "EMPTY"
75
76if !exists("dtd_no_param_entities")
77
78 " highlight parameter entity declarations
79 " and instances. Note that the closing `;'
80 " is optional.
81
82 " instances
83 syn region dtdParamEntityInst oneline matchgroup=dtdParamEntityPunct
84 \ start="%[-_a-zA-Z0-9.]\+"he=s+1,rs=s+1
85 \ skip=+[-_a-zA-Z0-9.]+
86 \ end=";\|\>"
87 \ matchgroup=NONE contains=dtdParamEntityPunct
88 syn match dtdParamEntityPunct contained "\."
89
90 " declarations
91 " syn region dtdParamEntityDecl oneline matchgroup=dtdParamEntityDPunct start=+<!ENTITY % +lc=8 skip=+[-_a-zA-Z0-9.]+ matchgroup=NONE end="\>" contains=dtdParamEntityDPunct
92 syn match dtdParamEntityDecl +<!ENTITY % [-_a-zA-Z0-9.]*+lc=8 contains=dtdParamEntityDPunct
93 syn match dtdParamEntityDPunct contained "%\|\."
94
95endif
96
97" &entities; compare with xml
98syn match dtdEntity "&[^; \t]*;" contains=dtdEntityPunct
99syn match dtdEntityPunct contained "[&.;]"
100
101" Strings are between quotes
Bram Moolenaarfa3b7232021-12-24 13:18:38 +0000102syn region dtdString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=dtdAttrDef,dtdAttrType,dtdParamEntityInst,dtdEntity,dtdCard
103syn region dtdString start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=dtdAttrDef,dtdAttrType,dtdParamEntityInst,dtdEntity,dtdCard
Bram Moolenaar071d4272004-06-13 20:20:40 +0000104
105" Enumeration of elements or data between parenthesis
106"
107" PROVIDES: @dtdEnumHook
108"
109syn region dtdEnum matchgroup=dtdType start="(" end=")" matchgroup=NONE contains=dtdEnum,dtdParamEntityInst,dtdCard,@dtdEnumHook
110
111"Attribute types
112syn keyword dtdAttrType NMTOKEN ENTITIES NMTOKENS ID CDATA
113syn keyword dtdAttrType IDREF IDREFS
114" ENTITY has to treated special for not overriding <!ENTITY
115syn match dtdAttrType +[^!]\<ENTITY+
116
117"Attribute Definitions
118syn match dtdAttrDef "#REQUIRED"
119syn match dtdAttrDef "#IMPLIED"
120syn match dtdAttrDef "#FIXED"
121
122syn case match
123" define some common keywords to mark TODO
124" and important sections inside comments.
125syn keyword dtdTodo contained TODO FIXME XXX
126
127syn sync lines=250
128
129" Define the default highlighting.
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200130" Only when an item doesn't have highlighting yet
Bram Moolenaar071d4272004-06-13 20:20:40 +0000131
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200132" The default highlighting.
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200133hi def link dtdFunction Function
134hi def link dtdTag Normal
135hi def link dtdType Type
136hi def link dtdAttrType dtdType
137hi def link dtdAttrDef dtdType
138hi def link dtdConstant Constant
139hi def link dtdString dtdConstant
140hi def link dtdEnum dtdConstant
141hi def link dtdCard dtdFunction
Bram Moolenaar071d4272004-06-13 20:20:40 +0000142
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200143hi def link dtdEntity Statement
144hi def link dtdEntityPunct dtdType
145hi def link dtdParamEntityInst dtdConstant
146hi def link dtdParamEntityPunct dtdType
147hi def link dtdParamEntityDecl dtdType
148hi def link dtdParamEntityDPunct dtdComment
Bram Moolenaar071d4272004-06-13 20:20:40 +0000149
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200150hi def link dtdComment Comment
151hi def link dtdTagName Statement
152hi def link dtdError Error
153hi def link dtdTodo Todo
Bram Moolenaar071d4272004-06-13 20:20:40 +0000154
Bram Moolenaar071d4272004-06-13 20:20:40 +0000155
Bram Moolenaar8e52a592012-05-18 21:49:28 +0200156let &cpo = s:dtd_cpo_save
157unlet s:dtd_cpo_save
Bram Moolenaar071d4272004-06-13 20:20:40 +0000158
159let b:current_syntax = "dtd"
160
161" vim: ts=8