2 " Language: Cascading Style Sheets
3 " Maintainer: Claudio Fleiner <claudio@fleiner.com>
4 " URL: http://www.fleiner.com/vim/syntax/css.vim
5 " Last Change: 2006 Jun 19
6 " CSS2 by Nikolai Weibull
7 " Full CSS2, HTML4 support by Yeti
9 " For version 5.x: Clear all syntax items
10 " For version 6.x: Quit when a syntax file was already loaded
11 if !exists("main_syntax")
14 elseif exists("b:current_syntax")
17 let main_syntax = 'css'
22 syn keyword cssTagName abbr acronym address applet area a b base
23 syn keyword cssTagName basefont bdo big blockquote body br button
24 syn keyword cssTagName caption center cite code col colgroup dd del
25 syn keyword cssTagName dfn dir div dl dt em fieldset font form frame
26 syn keyword cssTagName frameset h1 h2 h3 h4 h5 h6 head hr html img i
27 syn keyword cssTagName iframe img input ins isindex kbd label legend li
28 syn keyword cssTagName link map menu meta noframes noscript ol optgroup
29 syn keyword cssTagName option p param pre q s samp script select small
30 syn keyword cssTagName span strike strong style sub sup tbody td
31 syn keyword cssTagName textarea tfoot th thead title tr tt ul u var
32 syn match cssTagName "\<table\>"
33 syn match cssTagName "\*"
35 syn match cssTagName "@page\>" nextgroup=cssDefinition
37 syn match cssSelectorOp "[+>.]"
38 syn match cssSelectorOp2 "[~|]\?=" contained
39 syn region cssAttributeSelector matchgroup=cssSelectorOp start="\[" end="]" transparent contains=cssUnicodeEscape,cssSelectorOp2,cssStringQ,cssStringQQ
42 syn match cssIdentifier "#[A-Za-zÀ-ÿ_@][A-Za-zÀ-ÿ0-9_@-]*"
44 syn match cssIdentifier "#[A-Za-z_@][A-Za-z0-9_@-]*"
48 syn match cssMedia "@media\>" nextgroup=cssMediaType skipwhite skipnl
49 syn keyword cssMediaType contained screen print aural braile embosed handheld projection ty tv all nextgroup=cssMediaComma,cssMediaBlock skipwhite skipnl
50 syn match cssMediaComma "," nextgroup=cssMediaType skipwhite skipnl
51 syn region cssMediaBlock transparent matchgroup=cssBraces start='{' end='}' contains=cssTagName,cssError,cssComment,cssDefinition,cssURL,cssUnicodeEscape,cssIdentifier
53 syn match cssValueInteger contained "[-+]\=\d\+"
54 syn match cssValueNumber contained "[-+]\=\d\+\(\.\d*\)\="
55 syn match cssValueLength contained "[-+]\=\d\+\(\.\d*\)\=\(%\|mm\|cm\|in\|pt\|pc\|em\|ex\|px\)"
56 syn match cssValueAngle contained "[-+]\=\d\+\(\.\d*\)\=\(deg\|grad\|rad\)"
57 syn match cssValueTime contained "+\=\d\+\(\.\d*\)\=\(ms\|s\)"
58 syn match cssValueFrequency contained "+\=\d\+\(\.\d*\)\=\(Hz\|kHz\)"
60 syn match cssFontDescriptor "@font-face\>" nextgroup=cssFontDescriptorBlock skipwhite skipnl
61 syn region cssFontDescriptorBlock contained transparent matchgroup=cssBraces start="{" end="}" contains=cssComment,cssError,cssUnicodeEscape,cssFontProp,cssFontAttr,cssCommonAttr,cssStringQ,cssStringQQ,cssFontDescriptorProp,cssValue.*,cssFontDescriptorFunction,cssUnicodeRange,cssFontDescriptorAttr
62 syn match cssFontDescriptorProp contained "\<\(unicode-range\|unit-per-em\|panose-1\|cap-height\|x-height\|definition-src\)\>"
63 syn keyword cssFontDescriptorProp contained src stemv stemh slope ascent descent widths bbox baseline centerline mathline topline
64 syn keyword cssFontDescriptorAttr contained all
65 syn region cssFontDescriptorFunction contained matchgroup=cssFunctionName start="\<\(uri\|url\|local\|format\)\s*(" end=")" contains=cssStringQ,cssStringQQ oneline keepend
66 syn match cssUnicodeRange contained "U+[0-9A-Fa-f?]\+"
67 syn match cssUnicodeRange contained "U+\x\+-\x\+"
69 syn keyword cssColor contained aqua black blue fuchsia gray green lime maroon navy olive purple red silver teal yellow
70 " FIXME: These are actually case-insentivie too, but (a) specs recommend using
71 " mixed-case (b) it's hard to highlight the word `Background' correctly in
74 syn keyword cssColor contained ActiveBorder ActiveCaption AppWorkspace ButtonFace ButtonHighlight ButtonShadow ButtonText CaptionText GrayText Highlight HighlightText InactiveBorder InactiveCaption InactiveCaptionText InfoBackground InfoText Menu MenuText Scrollbar ThreeDDarkShadow ThreeDFace ThreeDHighlight ThreeDLightShadow ThreeDShadow Window WindowFrame WindowText Background
76 syn match cssColor contained "\<transparent\>"
77 syn match cssColor contained "\<white\>"
78 syn match cssColor contained "#[0-9A-Fa-f]\{3\}\>"
79 syn match cssColor contained "#[0-9A-Fa-f]\{6\}\>"
80 "syn match cssColor contained "\<rgb\s*(\s*\d\+\(\.\d*\)\=%\=\s*,\s*\d\+\(\.\d*\)\=%\=\s*,\s*\d\+\(\.\d*\)\=%\=\s*)"
81 syn region cssURL contained matchgroup=cssFunctionName start="\<url\s*(" end=")" oneline keepend
82 syn region cssFunction contained matchgroup=cssFunctionName start="\<\(rgb\|clip\|attr\|counter\|rect\)\s*(" end=")" oneline keepend
84 syn match cssImportant contained "!\s*important\>"
86 syn keyword cssCommonAttr contained auto none inherit
87 syn keyword cssCommonAttr contained top bottom
88 syn keyword cssCommonAttr contained medium normal
90 syn match cssFontProp contained "\<font\>\(-\(family\|style\|variant\|weight\|size\(-adjust\)\=\|stretch\)\>\)\="
91 syn match cssFontAttr contained "\<\(sans-\)\=\<serif\>"
92 syn match cssFontAttr contained "\<small\>\(-\(caps\|caption\)\>\)\="
93 syn match cssFontAttr contained "\<x\{1,2\}-\(large\|small\)\>"
94 syn match cssFontAttr contained "\<message-box\>"
95 syn match cssFontAttr contained "\<status-bar\>"
96 syn match cssFontAttr contained "\<\(\(ultra\|extra\|semi\|status-bar\)-\)\=\(condensed\|expanded\)\>"
97 syn keyword cssFontAttr contained cursive fantasy monospace italic oblique
98 syn keyword cssFontAttr contained bold bolder lighter larger smaller
99 syn keyword cssFontAttr contained icon menu
100 syn match cssFontAttr contained "\<caption\>"
101 syn keyword cssFontAttr contained large smaller larger
102 syn keyword cssFontAttr contained narrower wider
104 syn keyword cssColorProp contained color
105 syn match cssColorProp contained "\<background\(-\(color\|image\|attachment\|position\)\)\="
106 syn keyword cssColorAttr contained center scroll fixed
107 syn match cssColorAttr contained "\<repeat\(-[xy]\)\=\>"
108 syn match cssColorAttr contained "\<no-repeat\>"
110 syn match cssTextProp "\<\(\(word\|letter\)-spacing\|text\(-\(decoration\|transform\|align\|index\|shadow\)\)\=\|vertical-align\|unicode-bidi\|line-height\)\>"
111 syn match cssTextAttr contained "\<line-through\>"
112 syn match cssTextAttr contained "\<text-indent\>"
113 syn match cssTextAttr contained "\<\(text-\)\=\(top\|bottom\)\>"
114 syn keyword cssTextAttr contained underline overline blink sub super middle
115 syn keyword cssTextAttr contained capitalize uppercase lowercase center justify baseline sub super
117 syn match cssBoxProp contained "\<\(margin\|padding\|border\)\(-\(top\|right\|bottom\|left\)\)\=\>"
118 syn match cssBoxProp contained "\<border-\(\(\(top\|right\|bottom\|left\)-\)\=\(width\|color\|style\)\)\=\>"
119 syn match cssBoxProp contained "\<\(width\|z-index\)\>"
120 syn match cssBoxProp contained "\<\(min\|max\)-\(width\|height\)\>"
121 syn keyword cssBoxProp contained width height float clear overflow clip visibility
122 syn keyword cssBoxAttr contained thin thick both
123 syn keyword cssBoxAttr contained dotted dashed solid double groove ridge inset outset
124 syn keyword cssBoxAttr contained hidden visible scroll collapse
126 syn keyword cssGeneratedContentProp contained content quotes
127 syn match cssGeneratedContentProp contained "\<counter-\(reset\|increment\)\>"
128 syn match cssGeneratedContentProp contained "\<list-style\(-\(type\|position\|image\)\)\=\>"
129 syn match cssGeneratedContentAttr contained "\<\(no-\)\=\(open\|close\)-quote\>"
130 syn match cssAuralAttr contained "\<lower\>"
131 syn match cssGeneratedContentAttr contained "\<\(lower\|upper\)-\(roman\|alpha\|greek\|latin\)\>"
132 syn match cssGeneratedContentAttr contained "\<\(hiragana\|katakana\)\(-iroha\)\=\>"
133 syn match cssGeneratedContentAttr contained "\<\(decimal\(-leading-zero\)\=\|cjk-ideographic\)\>"
134 syn keyword cssGeneratedContentAttr contained disc circle square hebrew armenian georgian
135 syn keyword cssGeneratedContentAttr contained inside outside
137 syn match cssPagingProp contained "\<page\(-break-\(before\|after\|inside\)\)\=\>"
138 syn keyword cssPagingProp contained size marks inside orphans widows
139 syn keyword cssPagingAttr contained landscape portrait crop cross always avoid
141 syn keyword cssUIProp contained cursor
142 syn match cssUIProp contained "\<outline\(-\(width\|style\|color\)\)\=\>"
143 syn match cssUIAttr contained "\<[ns]\=[ew]\=-resize\>"
144 syn keyword cssUIAttr contained default crosshair pointer move wait help
145 syn keyword cssUIAttr contained thin thick
146 syn keyword cssUIAttr contained dotted dashed solid double groove ridge inset outset
147 syn keyword cssUIAttr contained invert
149 syn match cssRenderAttr contained "\<marker\>"
150 syn match cssRenderProp contained "\<\(display\|marker-offset\|unicode-bidi\|white-space\|list-item\|run-in\|inline-table\)\>"
151 syn keyword cssRenderProp contained position top bottom direction
152 syn match cssRenderProp contained "\<\(left\|right\)\>"
153 syn keyword cssRenderAttr contained block inline compact
154 syn match cssRenderAttr contained "\<table\(-\(row-gorup\|\(header\|footer\)-group\|row\|column\(-group\)\=\|cell\|caption\)\)\=\>"
155 syn keyword cssRenderAttr contained static relative absolute fixed
156 syn keyword cssRenderAttr contained ltr rtl embed bidi-override pre nowrap
157 syn match cssRenderAttr contained "\<bidi-override\>"
160 syn match cssAuralProp contained "\<\(pause\|cue\)\(-\(before\|after\)\)\=\>"
161 syn match cssAuralProp contained "\<\(play-during\|speech-rate\|voice-family\|pitch\(-range\)\=\|speak\(-\(punctuation\|numerals\)\)\=\)\>"
162 syn keyword cssAuralProp contained volume during azimuth elevation stress richness
163 syn match cssAuralAttr contained "\<\(x-\)\=\(soft\|loud\)\>"
164 syn keyword cssAuralAttr contained silent
165 syn match cssAuralAttr contained "\<spell-out\>"
166 syn keyword cssAuralAttr contained non mix
167 syn match cssAuralAttr contained "\<\(left\|right\)-side\>"
168 syn match cssAuralAttr contained "\<\(far\|center\)-\(left\|center\|right\)\>"
169 syn keyword cssAuralAttr contained leftwards rightwards behind
170 syn keyword cssAuralAttr contained below level above higher
171 syn match cssAuralAttr contained "\<\(x-\)\=\(slow\|fast\)\>"
172 syn keyword cssAuralAttr contained faster slower
173 syn keyword cssAuralAttr contained male female child code digits continuous
175 syn match cssTableProp contained "\<\(caption-side\|table-layout\|border-collapse\|border-spacing\|empty-cells\|speak-header\)\>"
176 syn keyword cssTableAttr contained fixed collapse separate show hide once always
178 " FIXME: This allows cssMediaBlock before the semicolon, which is wrong.
179 syn region cssInclude start="@import" end=";" contains=cssComment,cssURL,cssUnicodeEscape,cssMediaType
180 syn match cssBraces contained "[{}]"
181 syn match cssError contained "{@<>"
182 syn region cssDefinition transparent matchgroup=cssBraces start='{' end='}' contains=css.*Attr,css.*Prop,cssComment,cssValue.*,cssColor,cssURL,cssImportant,cssError,cssStringQ,cssStringQQ,cssFunction,cssUnicodeEscape
183 syn match cssBraceError "}"
185 syn match cssPseudoClass ":\S*" contains=cssPseudoClassId,cssUnicodeEscape
186 syn keyword cssPseudoClassId contained link visited active hover focus before after left right
187 syn match cssPseudoClassId contained "\<first\(-\(line\|letter\|child\)\)\=\>"
188 syn region cssPseudoClassLang matchgroup=cssPseudoClassId start=":lang(" end=")" oneline
190 syn region cssComment start="/\*" end="\*/" contains=@Spell
192 syn match cssUnicodeEscape "\\\x\{1,6}\s\?"
193 syn match cssSpecialCharQQ +\\"+ contained
194 syn match cssSpecialCharQ +\\'+ contained
195 syn region cssStringQQ start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=cssUnicodeEscape,cssSpecialCharQQ
196 syn region cssStringQ start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=cssUnicodeEscape,cssSpecialCharQ
197 syn match cssClassName "\.[A-Za-z][A-Za-z0-9-]\+"
199 if main_syntax == "css"
203 " Define the default highlighting.
204 " For version 5.7 and earlier: only when not done already
205 " For version 5.8 and later: only when an item doesn't have highlighting yet
206 if version >= 508 || !exists("did_css_syn_inits")
208 let did_css_syn_inits = 1
209 command -nargs=+ HiLink hi link <args>
211 command -nargs=+ HiLink hi def link <args>
214 HiLink cssComment Comment
215 HiLink cssTagName Statement
216 HiLink cssSelectorOp Special
217 HiLink cssSelectorOp2 Special
218 HiLink cssFontProp StorageClass
219 HiLink cssColorProp StorageClass
220 HiLink cssTextProp StorageClass
221 HiLink cssBoxProp StorageClass
222 HiLink cssRenderProp StorageClass
223 HiLink cssAuralProp StorageClass
224 HiLink cssRenderProp StorageClass
225 HiLink cssGeneratedContentProp StorageClass
226 HiLink cssPagingProp StorageClass
227 HiLink cssTableProp StorageClass
228 HiLink cssUIProp StorageClass
229 HiLink cssFontAttr Type
230 HiLink cssColorAttr Type
231 HiLink cssTextAttr Type
232 HiLink cssBoxAttr Type
233 HiLink cssRenderAttr Type
234 HiLink cssAuralAttr Type
235 HiLink cssGeneratedContentAttr Type
236 HiLink cssPagingAttr Type
237 HiLink cssTableAttr Type
238 HiLink cssUIAttr Type
239 HiLink cssCommonAttr Type
240 HiLink cssPseudoClassId PreProc
241 HiLink cssPseudoClassLang Constant
242 HiLink cssValueLength Number
243 HiLink cssValueInteger Number
244 HiLink cssValueNumber Number
245 HiLink cssValueAngle Number
246 HiLink cssValueTime Number
247 HiLink cssValueFrequency Number
248 HiLink cssFunction Constant
250 HiLink cssFunctionName Function
251 HiLink cssColor Constant
252 HiLink cssIdentifier Function
253 HiLink cssInclude Include
254 HiLink cssImportant Special
255 HiLink cssBraces Function
256 HiLink cssBraceError Error
257 HiLink cssError Error
258 HiLink cssInclude Include
259 HiLink cssUnicodeEscape Special
260 HiLink cssStringQQ String
261 HiLink cssStringQ String
262 HiLink cssMedia Special
263 HiLink cssMediaType Special
264 HiLink cssMediaComma Normal
265 HiLink cssFontDescriptor Special
266 HiLink cssFontDescriptorFunction Constant
267 HiLink cssFontDescriptorProp StorageClass
268 HiLink cssFontDescriptorAttr Type
269 HiLink cssUnicodeRange Constant
270 HiLink cssClassName Function
274 let b:current_syntax = "css"
276 if main_syntax == 'css'