Skip to content

Commit c959165

Browse files
committed
html4 close tag compatibility
1 parent 5b491f5 commit c959165

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

indent/html.vim

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -258,28 +258,28 @@ let s:html_indent_tags = '[a-z_][a-z0-9_.-]*'
258258
let s:cpo_save = &cpo
259259
set cpo-=C
260260

261-
" [-- count self close tags of line a:lnum --]
262-
fun! <SID>HtmlIndentAloneClose(lnum)
263-
let s = substitute('x'.getline(a:lnum),
264-
\ '.\{-}\(/>\)', "\1", 'g')
261+
func! <SID>HtmlIndentPatternCount(content, pattern)
262+
let s = substitute('x'.a:content, a:pattern, "\1", 'g')
265263
let s = substitute(s, "[^\1].*$", '', '')
266264
return strlen(s)
267265
endfun
268266

269267
" [-- count indent-increasing tags of line a:lnum --]
270268
fun! <SID>HtmlIndentOpen(lnum, pattern)
271-
let s = substitute('x'.getline(a:lnum),
272-
\ '.\{-}\(\(<\)\('.a:pattern.'\)\>\)', "\1", 'g')
273-
let s = substitute(s, "[^\1].*$", '', '')
274-
return strlen(s)
269+
return <SID>HtmlIndentPatternCount(getline(a:lnum),
270+
\ '.\{-}\(\(<\)\('.a:pattern.'\)\>\)')
275271
endfun
276272

277273
" [-- count indent-decreasing tags of line a:lnum --]
278274
fun! <SID>HtmlIndentClose(lnum, pattern)
279-
let s = substitute('x'.getline(a:lnum),
280-
\ '.\{-}\(\(<\)/\('.a:pattern.'\)\>>\)', "\1", 'g')
281-
let s = substitute(s, "[^\1].*$", '', '')
282-
return strlen(s)
275+
return <SID>HtmlIndentPatternCount(getline(a:lnum),
276+
\ '.\{-}\(\(<\)/\('.a:pattern.'\)\>>\)')
277+
endfun
278+
279+
" [-- count self close tags of line a:lnum --]
280+
fun! <SID>HtmlIndentSelfClose(lnum, pattern)
281+
return <SID>HtmlIndentPatternCount(getline(a:lnum),
282+
\ '.\{-}\(\(<\('.a:pattern.'\).*\)\@<!\/>\)')
283283
endfun
284284

285285
" [-- count indent-increasing '{' of (java|css) line a:lnum --]
@@ -298,9 +298,9 @@ fun! <SID>HtmlIndentSum(lnum, style)
298298
if a:style == match(getline(a:lnum), '^\s*</\<\('.s:html_indent_tags.'\)\>')
299299
let open = <SID>HtmlIndentOpen(a:lnum, s:html_indent_tags) - <SID>HtmlIndentOpen(a:lnum, s:html_noindent_tags)
300300
let close = <SID>HtmlIndentClose(a:lnum, s:html_indent_tags) - <SID>HtmlIndentClose(a:lnum, s:html_noindent_tags)
301-
\ + <SID>HtmlIndentAloneClose(a:lnum)
302-
if 0 != open || 0 != close
303-
return open - close
301+
let self_close = <SID>HtmlIndentSelfClose(a:lnum, s:html_noindent_tags)
302+
if 0 != open || 0 != close || 0 != self_close
303+
return open - close - self_close
304304
endif
305305
endif
306306
endif

0 commit comments

Comments
 (0)