From bb3de8fa5e509d5f5faf173fd1a92635a0023274 Mon Sep 17 00:00:00 2001 From: Adam Stankiewicz Date: Thu, 8 Oct 2020 00:40:28 +0200 Subject: Fix markdown and other highlighting, #578 --- indent/html.vim | 76 ++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 28 deletions(-) (limited to 'indent') diff --git a/indent/html.vim b/indent/html.vim index 3b9c7eb4..1e56c85e 100644 --- a/indent/html.vim +++ b/indent/html.vim @@ -1,11 +1,10 @@ -if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'html5') == -1 +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'html') == -1 " Vim indent script for HTML -" Header: "{{{ " Maintainer: Bram Moolenaar " Original Author: Andy Wokula -" Last Change: 2017 Jun 13 -" Version: 1.0 +" Last Change: 2020 Jul 06 +" Version: 1.0 "{{{ " Description: HTML indent script with cached state for faster indenting on a " range of lines. " Supports template systems through hooks. @@ -58,6 +57,9 @@ let s:cpo_save = &cpo set cpo-=C "}}} +" Pattern to match the name of a tag, including custom elements. +let s:tagname = '\w\+\(-\w\+\)*' + " Check and process settings from b:html_indent and g:html_indent... variables. " Prefer using buffer-local settings over global settings, so that there can " be defaults for all HTML files and exceptions for specific types of HTML @@ -216,25 +218,27 @@ endfunc "}}} " Self-closing tags and tags that are sometimes {{{ " self-closing (e.g.,

) 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', 'del', 'dfn', 'dir', 'div', 'dl', 'em', 'fieldset', 'font', + \ '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', 'p', 'q', 's', 'samp', 'select', 'small', 'span', 'strong', 'sub', + \ '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, [ - \ 'area', 'article', 'aside', 'audio', 'bdi', 'canvas', - \ 'command', 'data', 'datalist', 'details', 'dislog', 'embed', 'figcaption', - \ 'figure', 'footer', 'header', 'keygen', 'main', 'mark', 'meter', 'nav', 'output', - \ 'picture', 'progress', 'rp', 'rt', 'ruby', 'section', 'source', 'summary', 'svg', - \ 'time', 'track', 'video', 'wbr']) + \ '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, [ @@ -282,7 +286,7 @@ func! s:CountITags(text) 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/\=\w\+\(-\w\+\)*\>\|\|', '\=s:CheckTag(submatch(0))', 'g') + call substitute(a:text, '<\zs/\=' . s:tagname . '\>\|\|', '\=s:CheckTag(submatch(0))', 'g') let s:countonly = 0 endfunc "}}} @@ -294,7 +298,7 @@ func! s:CountTagsAndState(text) 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/\=\w\+\(-\w\+\)*\>\|\|', '\=s:CheckTag(submatch(0))', 'g') + 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.*\zs[^>]*')) endif @@ -532,7 +536,7 @@ func! s:FreshState(lnum) let swendtag = match(text, '^\s*= 0 " If previous line ended in a closing tag, line up with the opening tag. - if !swendtag && text =~ '\s*$' + if !swendtag && text =~ '\s*$' call cursor(state.lnum, 99999) normal! F< let start_lnum = HtmlIndent_FindStartTag() @@ -584,7 +588,7 @@ func! s:Alien3() return eval(b:hi_js1indent) endif if b:hi_indent.scripttype == "javascript" - return GetJavascriptIndent() + return eval(b:hi_js1indent) + GetJavascriptIndent() else return -1 endif @@ -623,7 +627,7 @@ func! s:CSSIndent() return eval(b:hi_css1indent) endif - " If the current line starts with "}" align with it's match. + " If the current line starts with "}" align with its match. if curtext =~ '^\s*}' call cursor(v:lnum, 1) try @@ -661,7 +665,7 @@ func! s:CSSIndent() else let cur_hasfield = curtext =~ '^\s*[a-zA-Z0-9-]\+:' let prev_unfinished = s:CssUnfinished(prev_text) - if !cur_hasfield && (prev_hasfield || prev_unfinished) + if prev_unfinished " Continuation line has extra indent if the previous line was not a " continuation line. let extra = shiftwidth() @@ -714,9 +718,13 @@ func! s:CSSIndent() endfunc "}}} " Inside