blob: bd138e6bb8b69e96186ae612923ea6a074f9ffe8 [file] [log] [blame]
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001" Vim completion script
2" Language: XHTML 1.0 Strict
3" Maintainer: Mikolaj Machowski ( mikmach AT wp DOT pl )
Bram Moolenaara5792f52005-11-23 21:25:05 +00004" Last Change: 2005 Now 20
Bram Moolenaarf75a9632005-09-13 21:20:47 +00005
6function! htmlcomplete#CompleteTags(findstart, base)
7 if a:findstart
8 " locate the start of the word
9 let line = getline('.')
10 let start = col('.') - 1
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000011 let compl_begin = col('.') - 2
12 while start >= 0 && line[start - 1] =~ '\(\k\|[:.-]\)'
13 let start -= 1
Bram Moolenaarf75a9632005-09-13 21:20:47 +000014 endwhile
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000015 if start >= 0 && line[start - 1] =~ '&'
16 let b:entitiescompl = 1
17 let b:compl_context = ''
18 return start
19 endif
20 let stylestart = searchpair('<style\>', '', '<\/style\>', "bnW")
21 let styleend = searchpair('<style\>', '', '<\/style\>', "nW")
22 if stylestart != 0 && styleend != 0
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +000023 let curpos = line('.')
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000024 if stylestart <= curpos && styleend >= curpos
25 let start = col('.') - 1
26 let b:csscompl = 1
27 while start >= 0 && line[start - 1] =~ '\(\k\|-\)'
28 let start -= 1
29 endwhile
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +000030 endif
31 endif
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000032 if !exists("b:csscompl")
33 let b:compl_context = getline('.')[0:(compl_begin)]
34 let b:compl_context = matchstr(b:compl_context, '.*<\zs.*')
35 else
36 let b:compl_context = getline('.')[0:compl_begin]
37 endif
Bram Moolenaarf75a9632005-09-13 21:20:47 +000038 return start
39 else
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000040 " Initialize base return lists
41 let res = []
42 let res2 = []
43 " a:base is very short - we need context
44 let context = b:compl_context
45 unlet! b:compl_context
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +000046 " Check if we should do CSS completion inside of <style> tag
47 if exists("b:csscompl")
48 unlet! b:csscompl
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000049 return csscomplete#CompleteCSS(0, context)
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +000050 endif
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000051 " Make entities completion
52 if exists("b:entitiescompl")
53 unlet! b:entitiescompl
54
Bram Moolenaara5792f52005-11-23 21:25:05 +000055 if !exists("g:xmldata_xhtml10s")
56 runtime! autoload/xml/xhtml10s.vim
57 endif
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000058
Bram Moolenaara5792f52005-11-23 21:25:05 +000059 let entities = g:xmldata_xhtml10s['vimxmlentities']
60
61 for m in entities
Bram Moolenaar8349fd72005-10-12 20:52:20 +000062 if m =~ '^'.a:base
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000063 call add(res, m.';')
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000064 endif
65 endfor
66
Bram Moolenaar8349fd72005-10-12 20:52:20 +000067 return res
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000068
69 endif
70 if context =~ '>'
71 " Generally if context contains > it means we are outside of tag and
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +000072 " should abandon action - with one exception: <style> span { bo
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000073 if context =~ 'style[^>]\{-}>[^<]\{-}$'
74 return csscomplete#CompleteCSS(0, context)
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +000075 else
76 return []
77 endif
78 endif
79
Bram Moolenaarf75a9632005-09-13 21:20:47 +000080 " Set attribute groups
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +000081 let coreattrs = ["id", "class", "style", "title"]
82 let i18n = ["lang", "xml:lang", "dir=\"ltr\" ", "dir=\"rtl\" "]
83 let events = ["onclick", "ondblclick", "onmousedown", "onmouseup", "onmousemove",
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000084 \ "onmouseover", "onmouseout", "onkeypress", "onkeydown", "onkeyup"]
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +000085 let focus = ["accesskey", "tabindex", "onfocus", "onblur"]
86 let coregroup = coreattrs + i18n + events
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000087 " find tags matching with "context"
88 " If context contains > it means we are already outside of tag and we
Bram Moolenaarf75a9632005-09-13 21:20:47 +000089 " should abandon action
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000090 " If context contains white space it is attribute.
Bram Moolenaarf75a9632005-09-13 21:20:47 +000091 " It could be also value of attribute...
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +000092 " We have to get first word to offer
93 " proper completions
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000094 if context == ''
95 let tag = ''
96 else
97 let tag = split(context)[0]
98 endif
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +000099 " Get last word, it should be attr name
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000100 let attr = matchstr(context, '.*\s\zs.*')
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000101 " Possible situations where any prediction would be difficult:
102 " 1. Events attributes
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000103 if context =~ '\s'
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000104 " Sort out style, class, and on* cases
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000105 if context =~ "\\(on[a-z]*\\|id\\|style\\|class\\)\\s*=\\s*[\"']"
106 if context =~ "\\(id\\|class\\)\\s*=\\s*[\"'][a-zA-Z0-9_ -]*$"
107 if context =~ "class\\s*=\\s*[\"'][a-zA-Z0-9_ -]*$"
Bram Moolenaar1e015462005-09-25 22:16:38 +0000108 let search_for = "class"
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000109 elseif context =~ "id\\s*=\\s*[\"'][a-zA-Z0-9_ -]*$"
Bram Moolenaar1e015462005-09-25 22:16:38 +0000110 let search_for = "id"
111 endif
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000112 " Handle class name completion
113 " 1. Find lines of <link stylesheet>
114 " 1a. Check file for @import
115 " 2. Extract filename(s?) of stylesheet,
116 call cursor(1,1)
117 let head = getline(search('<head\>'), search('<\/head>'))
118 let headjoined = join(copy(head), ' ')
119 if headjoined =~ '<style'
Bram Moolenaara5792f52005-11-23 21:25:05 +0000120 " Remove possibly confusing CSS operators
Bram Moolenaar1e015462005-09-25 22:16:38 +0000121 let stylehead = substitute(headjoined, '+>\*[,', ' ', 'g')
122 if search_for == 'class'
123 let styleheadlines = split(stylehead)
124 let headclasslines = filter(copy(styleheadlines), "v:val =~ '\\([a-zA-Z0-9:]\\+\\)\\?\\.[a-zA-Z0-9_-]\\+'")
125 else
126 let stylesheet = split(headjoined, '[{}]')
127 " Get all lines which fit id syntax
128 let classlines = filter(copy(stylesheet), "v:val =~ '#[a-zA-Z0-9_-]\\+'")
129 " Filter out possible color definitions
130 call filter(classlines, "v:val !~ ':\\s*#[a-zA-Z0-9_-]\\+'")
131 " Filter out complex border definitions
132 call filter(classlines, "v:val !~ '\\(none\\|hidden\\|dotted\\|dashed\\|solid\\|double\\|groove\\|ridge\\|inset\\|outset\\)\\s*#[a-zA-Z0-9_-]\\+'")
133 let templines = join(classlines, ' ')
134 let headclasslines = split(templines)
135 call filter(headclasslines, "v:val =~ '#[a-zA-Z0-9_-]\\+'")
136 endif
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000137 let internal = 1
138 else
139 let internal = 0
140 endif
141 let styletable = []
142 let secimportfiles = []
143 let filestable = filter(copy(head), "v:val =~ '\\(@import\\|link.*stylesheet\\)'")
144 for line in filestable
145 if line =~ "@import"
146 let styletable += [matchstr(line, "import\\s\\+\\(url(\\)\\?[\"']\\?\\zs\\f\\+\\ze")]
147 elseif line =~ "<link"
148 let styletable += [matchstr(line, "href\\s*=\\s*[\"']\\zs\\f\\+\\ze")]
149 endif
150 endfor
Bram Moolenaar1e015462005-09-25 22:16:38 +0000151 for file in styletable
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000152 if filereadable(file)
153 let stylesheet = readfile(file)
154 let secimport = filter(copy(stylesheet), "v:val =~ '@import'")
155 if len(secimport) > 0
156 for line in secimport
Bram Moolenaar1e015462005-09-25 22:16:38 +0000157 let secfile = matchstr(line, "import\\s\\+\\(url(\\)\\?[\"']\\?\\zs\\f\\+\\ze")
158 let secfile = fnamemodify(file, ":p:h").'/'.secfile
159 let secimportfiles += [secfile]
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000160 endfor
161 endif
162 endif
163 endfor
164 let cssfiles = styletable + secimportfiles
165 let classes = []
166 for file in cssfiles
167 if filereadable(file)
168 let stylesheet = readfile(file)
Bram Moolenaar1e015462005-09-25 22:16:38 +0000169 let stylefile = join(stylesheet, ' ')
170 let stylefile = substitute(stylefile, '+>\*[,', ' ', 'g')
171 if search_for == 'class'
172 let stylesheet = split(stylefile)
173 let classlines = filter(copy(stylesheet), "v:val =~ '\\([a-zA-Z0-9:]\\+\\)\\?\\.[a-zA-Z0-9_-]\\+'")
174 else
175 let stylesheet = split(stylefile, '[{}]')
176 " Get all lines which fit id syntax
177 let classlines = filter(copy(stylesheet), "v:val =~ '#[a-zA-Z0-9_-]\\+'")
178 " Filter out possible color definitions
179 call filter(classlines, "v:val !~ ':\\s*#[a-zA-Z0-9_-]\\+'")
180 " Filter out complex border definitions
181 call filter(classlines, "v:val !~ '\\(none\\|hidden\\|dotted\\|dashed\\|solid\\|double\\|groove\\|ridge\\|inset\\|outset\\)\\s*#[a-zA-Z0-9_-]\\+'")
182 let templines = join(classlines, ' ')
183 let stylelines = split(templines)
184 let classlines = filter(stylelines, "v:val =~ '#[a-zA-Z0-9_-]\\+'")
185
186 endif
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000187 endif
188 " We gathered classes definitions from all external files
189 let classes += classlines
190 endfor
191 if internal == 1
192 let classes += headclasslines
193 endif
Bram Moolenaar1e015462005-09-25 22:16:38 +0000194
195 if search_for == 'class'
196 let elements = {}
197 for element in classes
198 if element =~ '^\.'
199 let class = matchstr(element, '^\.\zs[a-zA-Z][a-zA-Z0-9_-]*\ze')
200 let class = substitute(class, ':.*', '', '')
201 if has_key(elements, 'common')
202 let elements['common'] .= ' '.class
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000203 else
Bram Moolenaar1e015462005-09-25 22:16:38 +0000204 let elements['common'] = class
205 endif
206 else
207 let class = matchstr(element, '[a-zA-Z1-6]*\.\zs[a-zA-Z][a-zA-Z0-9_-]*\ze')
208 let tagname = tolower(matchstr(element, '[a-zA-Z1-6]*\ze.'))
209 if tagname != ''
210 if has_key(elements, tagname)
211 let elements[tagname] .= ' '.class
212 else
213 let elements[tagname] = class
214 endif
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000215 endif
216 endif
Bram Moolenaar1e015462005-09-25 22:16:38 +0000217 endfor
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000218
Bram Moolenaar1e015462005-09-25 22:16:38 +0000219 if has_key(elements, tag) && has_key(elements, 'common')
220 let values = split(elements[tag]." ".elements['common'])
221 elseif has_key(elements, tag) && !has_key(elements, 'common')
222 let values = split(elements[tag])
223 elseif !has_key(elements, tag) && has_key(elements, 'common')
224 let values = split(elements['common'])
225 else
226 return []
227 endif
228
229 elseif search_for == 'id'
230 " Find used IDs
231 " 1. Catch whole file
232 let filelines = getline(1, line('$'))
233 " 2. Find lines with possible id
234 let used_id_lines = filter(filelines, 'v:val =~ "id\\s*=\\s*[\"''][a-zA-Z0-9_-]\\+"')
235 " 3a. Join all filtered lines
236 let id_string = join(used_id_lines, ' ')
237 " 3b. And split them to be sure each id is in separate item
238 let id_list = split(id_string, 'id\s*=\s*')
239 " 4. Extract id values
240 let used_id = map(id_list, 'matchstr(v:val, "[\"'']\\zs[a-zA-Z0-9_-]\\+\\ze")')
241 let joined_used_id = ','.join(used_id, ',').','
242
243 let allvalues = map(classes, 'matchstr(v:val, ".*#\\zs[a-zA-Z0-9_-]\\+")')
244
245 let values = []
246
247 for element in classes
248 if joined_used_id !~ ','.element.','
249 let values += [element]
250 endif
251
252 endfor
253
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000254 endif
255
256 " We need special version of sbase
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000257 let classbase = matchstr(context, ".*[\"']")
Bram Moolenaar1e015462005-09-25 22:16:38 +0000258 let classquote = matchstr(classbase, '.$')
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000259
260 let entered_class = matchstr(attr, ".*=\\s*[\"']\\zs.*")
261
262 for m in sort(values)
263 if m =~? '^'.entered_class
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000264 call add(res, m . classquote)
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000265 elseif m =~? entered_class
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000266 call add(res2, m . classquote)
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000267 endif
268 endfor
269
270 return res + res2
271
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000272 elseif context =~ "style\\s*=\\s*[\"'][^\"']*$"
273 return csscomplete#CompleteCSS(0, context)
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000274
275 endif
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000276 let stripbase = matchstr(context, ".*\\(on[a-z]*\\|style\\|class\\)\\s*=\\s*[\"']\\zs.*")
277 " Now we have context stripped from all chars up to style/class.
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000278 " It may fail with some strange style value combinations.
279 if stripbase !~ "[\"']"
280 return []
281 endif
282 endif
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000283 " If attr contains =\s*[\"'] we catched value of attribute
284 if attr =~ "=\s*[\"']"
285 " Let do attribute specific completion
286 let attrname = matchstr(attr, '.*\ze\s*=')
287 let entered_value = matchstr(attr, ".*=\\s*[\"']\\zs.*")
288 let values = []
289 if attrname == 'media'
290 let values = ["screen", "tty", "tv", "projection", "handheld", "print", "braille", "aural", "all"]
291 elseif attrname == 'xml:space'
292 let values = ["preserve"]
293 elseif attrname == 'shape'
Bram Moolenaar8349fd72005-10-12 20:52:20 +0000294 let values = ["rect", "circle", "poly", "default"]
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000295 elseif attrname == 'valuetype'
296 let values = ["data", "ref", "object"]
297 elseif attrname == 'method'
298 let values = ["get", "post"]
Bram Moolenaar4c903f92005-09-14 21:32:32 +0000299 elseif attrname == 'dir'
300 let values = ["ltr", "rtl"]
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000301 elseif attrname == 'frame'
302 let values = ["void", "above", "below", "hsides", "lhs", "rhs", "vsides", "box", "border"]
303 elseif attrname == 'rules'
304 let values = ["none", "groups", "rows", "all"]
305 elseif attrname == 'align'
306 let values = ["left", "center", "right", "justify", "char"]
307 elseif attrname == 'valign'
308 let values = ["top", "middle", "bottom", "baseline"]
309 elseif attrname == 'scope'
310 let values = ["row", "col", "rowgroup", "colgroup"]
311 elseif attrname == 'href'
312 " Now we are looking for local anchors defined by name or id
313 if entered_value =~ '^#'
314 let file = join(getline(1, line('$')), ' ')
315 " Split it be sure there will be one id/name element in
316 " item, it will be also first word [a-zA-Z0-9_-] in element
317 let oneelement = split(file, "\\(meta \\)\\@<!\\(name\\|id\\)\\s*=\\s*[\"']")
318 for i in oneelement
319 let values += ['#'.matchstr(i, "^[a-zA-Z][a-zA-Z0-9%_-]*")]
320 endfor
321 endif
322 elseif attrname == 'type'
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000323 if context =~ '^input'
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000324 let values = ["text", "password", "checkbox", "radio", "submit", "reset", "file", "hidden", "image", "button"]
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000325 elseif context =~ '^button'
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000326 let values = ["button", "submit", "reset"]
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000327 elseif context =~ '^style'
Bram Moolenaar1e015462005-09-25 22:16:38 +0000328 let values = ["text/css"]
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000329 elseif context =~ '^script'
Bram Moolenaar1e015462005-09-25 22:16:38 +0000330 let values = ["text/javascript"]
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000331 endif
332 else
333 return []
334 endif
335
336 if len(values) == 0
337 return []
338 endif
339
340 " We need special version of sbase
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000341 let attrbase = matchstr(context, ".*[\"']")
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000342 let attrquote = matchstr(attrbase, '.$')
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000343
344 for m in values
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000345 " This if is needed to not offer all completions as-is
346 " alphabetically but sort them. Those beginning with entered
347 " part will be as first choices
348 if m =~ '^'.entered_value
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000349 call add(res, m . attrquote.' ')
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000350 elseif m =~ entered_value
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000351 call add(res2, m . attrquote.' ')
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000352 endif
353 endfor
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000354
355 return res + res2
356
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000357 endif
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000358 " Shorten context to not include last word
359 let sbase = matchstr(context, '.*\ze\s.*')
360 if tag =~ '^\(abbr\|acronym\|address\|b\|bdo\|big\|caption\|cite\|code\|dd\|dfn\|div\|dl\|dt\|em\|fieldset\|h\d\|hr\|i\|kbd\|li\|noscript\|ol\|p\|samp\|small\|span\|strong\|sub\|sup\|tt\|ul\|var\)$'
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000361 let attrs = coregroup
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000362 elseif tag == 'a'
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000363 let attrs = coregroup + focus + ["charset", "type", "name", "href", "hreflang", "rel", "rev", "shape", "coords"]
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000364 elseif tag == 'area'
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000365 let attrs = coregroup + focus + ["shape", "coords", "href", "nohref", "alt"]
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000366 elseif tag == 'base'
367 let attrs = ["href", "id"]
368 elseif tag == 'blockquote'
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000369 let attrs = coregroup + ["cite"]
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000370 elseif tag == 'body'
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000371 let attrs = coregroup + ["onload", "onunload"]
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000372 elseif tag == 'br'
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000373 let attrs = coreattrs
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000374 elseif tag == 'button'
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000375 let attrs = coregroup + focus + ["name", "value", "type"]
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000376 elseif tag == '^\(col\|colgroup\)$'
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000377 let attrs = coregroup + ["span", "width", "align", "char", "charoff", "valign"]
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000378 elseif tag =~ '^\(del\|ins\)$'
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000379 let attrs = coregroup + ["cite", "datetime"]
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000380 elseif tag == 'form'
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000381 let attrs = coregroup + ["action", "method=\"get\" ", "method=\"post\" ", "enctype", "onsubmit", "onreset", "accept", "accept-charset"]
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000382 elseif tag == 'head'
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000383 let attrs = i18n + ["id", "profile"]
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000384 elseif tag == 'html'
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000385 let attrs = i18n + ["id", "xmlns"]
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000386 elseif tag == 'img'
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000387 let attrs = coregroup + ["src", "alt", "longdesc", "height", "width", "usemap", "ismap"]
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000388 elseif tag == 'input'
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000389 let attrs = coregroup + ["type", "name", "value", "checked", "disabled", "readonly", "size", "maxlength", "src", "alt", "usemap", "onselect", "onchange", "accept"]
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000390 elseif tag == 'label'
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000391 let attrs = coregroup + ["for", "accesskey", "onfocus", "onblur"]
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000392 elseif tag == 'legend'
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000393 let attrs = coregroup + ["accesskey"]
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000394 elseif tag == 'link'
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000395 let attrs = coregroup + ["charset", "href", "hreflang", "type", "rel", "rev", "media"]
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000396 elseif tag == 'map'
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000397 let attrs = i18n + events + ["id", "class", "style", "title", "name"]
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000398 elseif tag == 'meta'
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000399 let attrs = i18n + ["id", "http-equiv", "content", "scheme", "name"]
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000400 elseif tag == 'title'
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000401 let attrs = i18n + ["id"]
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000402 elseif tag == 'object'
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000403 let attrs = coregroup + ["declare", "classid", "codebase", "data", "type", "codetype", "archive", "standby", "height", "width", "usemap", "name", "tabindex"]
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000404 elseif tag == 'optgroup'
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000405 let attrs = coregroup + ["disbled", "label"]
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000406 elseif tag == 'option'
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000407 let attrs = coregroup + ["disbled", "selected", "value", "label"]
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000408 elseif tag == 'param'
409 let attrs = ["id", "name", "value", "valuetype", "type"]
410 elseif tag == 'pre'
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000411 let attrs = coregroup + ["xml:space"]
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000412 elseif tag == 'q'
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000413 let attrs = coregroup + ["cite"]
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000414 elseif tag == 'script'
Bram Moolenaar1e015462005-09-25 22:16:38 +0000415 let attrs = ["id", "charset", "type=\"text/javascript\"", "type", "src", "defer", "xml:space"]
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000416 elseif tag == 'select'
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000417 let attrs = coregroup + ["name", "size", "multiple", "disabled", "tabindex", "onfocus", "onblur", "onchange"]
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000418 elseif tag == 'style'
Bram Moolenaar1e015462005-09-25 22:16:38 +0000419 let attrs = coreattrs + ["id", "type=\"text/css\"", "type", "media", "title", "xml:space"]
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000420 elseif tag == 'table'
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000421 let attrs = coregroup + ["summary", "width", "border", "frame", "rules", "cellspacing", "cellpadding"]
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000422 elseif tag =~ '^\(thead\|tfoot\|tbody\|tr\)$'
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000423 let attrs = coregroup + ["align", "char", "charoff", "valign"]
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000424 elseif tag == 'textarea'
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000425 let attrs = coregroup + ["name", "rows", "cols", "disabled", "readonly", "onselect", "onchange"]
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000426 elseif tag =~ '^\(th\|td\)$'
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000427 let attrs = coregroup + ["abbr", "headers", "scope", "rowspan", "colspan", "align", "char", "charoff", "valign"]
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000428 else
429 return []
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000430 endif
431
432 for m in sort(attrs)
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000433 if m =~ '^'.attr
434 if m =~ '^\(ismap\|defer\|declare\|nohref\|checked\|disabled\|selected\|readonly\)$' || m =~ '='
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000435 call add(res, m)
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000436 else
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000437 call add(res, m.'="')
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000438 endif
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000439 elseif m =~ attr
440 if m =~ '^\(ismap\|defer\|declare\|nohref\|checked\|disabled\|selected\|readonly\)$' || m =~ '='
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000441 call add(res2, m)
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000442 else
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000443 call add(res2, m.'="')
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000444 endif
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000445 endif
446 endfor
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000447
448 return res + res2
449
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000450 endif
Bram Moolenaar4c903f92005-09-14 21:32:32 +0000451 " Close tag
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000452 let b:unaryTagsStack = "base meta link hr br param img area input col"
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000453 if context =~ '^\/'
Bram Moolenaara5792f52005-11-23 21:25:05 +0000454 let opentag = xmlcomplete#GetLastOpenTag("b:unaryTagsStack")
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000455 return [opentag.">"]
Bram Moolenaar4c903f92005-09-14 21:32:32 +0000456 endif
457 " Deal with tag completion.
Bram Moolenaara5792f52005-11-23 21:25:05 +0000458 let opentag = xmlcomplete#GetLastOpenTag("b:unaryTagsStack")
Bram Moolenaar4c903f92005-09-14 21:32:32 +0000459
Bram Moolenaara5792f52005-11-23 21:25:05 +0000460 if !exists("g:xmldata_xhtml10s")
461 runtime! autoload/xml/xhtml10s.vim
Bram Moolenaar4c903f92005-09-14 21:32:32 +0000462 endif
463
Bram Moolenaara5792f52005-11-23 21:25:05 +0000464 let tags = g:xmldata_xhtml10s[opentag][0]
465
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000466 for m in tags
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000467 if m =~ '^'.context
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000468 call add(res, m)
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000469 elseif m =~ context
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000470 call add(res2, m)
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000471 endif
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000472 endfor
473
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +0000474 return res + res2
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000475
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000476 endif
477endfunction