) are not here (when encountering
we can find " the matching, but not the other way around). " Known self-closing tags: " 'p', 'img', 'source', 'area', 'keygen', 'track', " 'wbr'. " Old HTML tags: call s:AddITags(s:indent_tags, [ \ 'a', 'abbr', 'acronym', 'address', 'b', 'bdo', 'big', \ 'blockquote', 'body', 'button', 'caption', 'center', 'cite', 'code', \ 'colgroup', 'dd', 'del', 'dfn', 'dir', 'div', 'dl', 'dt', 'em', 'fieldset', 'font', \ 'form', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'html', \ 'i', 'iframe', 'ins', 'kbd', 'label', 'legend', 'li', \ 'map', 'menu', 'noframes', 'noscript', 'object', 'ol', \ 'optgroup', 'q', 's', 'samp', 'select', 'small', 'span', 'strong', 'sub', \ 'sup', 'table', 'textarea', 'title', 'tt', 'u', 'ul', 'var', 'th', 'td', \ 'tr', 'tbody', 'tfoot', 'thead']) " New HTML5 elements: call s:AddITags(s:indent_tags, [ \ 'article', 'aside', 'audio', 'bdi', 'canvas', 'command', 'data', \ 'datalist', 'details', 'dialog', 'embed', 'figcaption', 'figure', \ 'footer', 'header', 'hgroup', 'main', 'mark', 'meter', 'nav', 'output', \ 'picture', 'progress', 'rp', 'rt', 'ruby', 'section', 'summary', \ 'svg', 'time', 'video']) " Tags added for web components: call s:AddITags(s:indent_tags, [ \ 'content', 'shadow', 'template']) "}}} " Add Block Tags: these contain alien content "{{{ call s:AddBlockTag('pre', 2) call s:AddBlockTag('script', 3) call s:AddBlockTag('style', 4) call s:AddBlockTag('') call s:AddBlockTag('') "}}} " Return non-zero when "tagname" is an opening tag, not being a block tag, for " which there should be a closing tag. Can be used by scripts that include " HTML indenting. func HtmlIndent_IsOpenTag(tagname) "{{{ if get(s:indent_tags, a:tagname) == 1 return 1 endif return get(b:hi_tags, a:tagname) == 1 endfunc "}}} " Get the value for "tagname", taking care of buffer-local tags. func s:get_tag(tagname) "{{{ let i = get(s:indent_tags, a:tagname) if (i == 1 || i == -1) && get(b:hi_removed_tags, a:tagname) != 0 return 0 endif if i == 0 let i = get(b:hi_tags, a:tagname) endif return i endfunc "}}} " Count the number of start and end tags in "text". func s:CountITags(text) "{{{ " Store the result in s:curind and s:nextrel. let s:curind = 0 " relative indent steps for current line [unit &sw]: let s:nextrel = 0 " relative indent steps for next line [unit &sw]: let s:block = 0 " assume starting outside of a block let s:countonly = 1 " don't change state call substitute(a:text, '<\zs/\=' . s:tagname . '\>\|\|', '\=s:CheckTag(submatch(0))', 'g') let s:countonly = 0 endfunc "}}} " Count the number of start and end tags in text. func s:CountTagsAndState(text) "{{{ " Store the result in s:curind and s:nextrel. Update b:hi_newstate.block. let s:curind = 0 " relative indent steps for current line [unit &sw]: let s:nextrel = 0 " relative indent steps for next line [unit &sw]: let s:block = b:hi_newstate.block let tmp = substitute(a:text, '<\zs/\=' . s:tagname . '\>\|\|', '\=s:CheckTag(submatch(0))', 'g') if s:block == 3 let b:hi_newstate.scripttype = s:GetScriptType(matchstr(tmp, '\C.*) " if comment opener found, " assume a:lnum within comment " else " assume usual html for a:lnum " if a:lnum-1 has a closing comment " look back to get indent of comment opener " FI " look back for a blocktag let stopline2 = v:lnum + 1 if has_key(b:hi_indent, 'block') && b:hi_indent.block > 5 let [stopline2, stopcol2] = searchpos('', 'bpnW', stopline) if found == 2 || found == 3 " comment opener found, assume a:lnum within comment let state.block = (found == 3 ? 5 : 6) let state.blocklnr = comlnum " check preceding tags in the line: call s:CountITags(tolower(getline(comlnum)[: comcol-2])) if found == 2 let state.baseindent = b:hi_indent.baseindent endif let state.blocktagind = indent(comlnum) + (s:curind + s:nextrel) * shiftwidth() return state endif " else within usual HTML let text = tolower(getline(state.lnum)) " Check a:lnum-1 for closing comment (we need indent from the opening line). " Not when other tags follow (might be --> inside a string). let comcol = stridx(text, '-->') if comcol >= 0 && match(text, '[<>]', comcol) <= 0 call cursor(state.lnum, comcol + 1) let [comlnum, comcol] = searchpos('" return state endif " Check if the previous line starts with end tag. let swendtag = match(text, '^\s*') >= 0 " If previous line ended in a closing tag, line up with the opening tag. if !swendtag && text =~ '' . s:tagname . '\s*>\s*$' call cursor(state.lnum, 99999) normal! F< let start_lnum = HtmlIndent_FindStartTag() if start_lnum > 0 let state.baseindent = indent(start_lnum) if col('.') > 2 " check for tags before the matching opening tag. let text = getline(start_lnum) let swendtag = match(text, '^\s*') >= 0 call s:CountITags(text[: col('.') - 2]) let state.baseindent += s:nextrel * shiftwidth() if !swendtag let state.baseindent += s:curind * shiftwidth() endif endif return state endif endif " Else: no comments. Skip backwards to find the tag we're inside. let [state.lnum, found] = HtmlIndent_FindTagStart(state.lnum) " Check if that line starts with end tag. let text = getline(state.lnum) let swendtag = match(text, '^\s*') >= 0 call s:CountITags(tolower(text)) let state.baseindent = indent(state.lnum) + s:nextrel * shiftwidth() if !swendtag let state.baseindent += s:curind * shiftwidth() endif return state endfunc "}}} " Indent inside a
block: Keep indent as-is. func s:Alien2() "{{{ return -1 endfunc "}}} " Return the indent inside a