mirror of
https://github.com/mattn/emmet-vim.git
synced 2025-12-10 20:41:54 +08:00
supported 'e' filter and 'c' filter.
This commit is contained in:
@@ -1021,6 +1021,11 @@ function! s:zen_toString(...)
|
|||||||
else
|
else
|
||||||
let inline = 0
|
let inline = 0
|
||||||
endif
|
endif
|
||||||
|
if a:0 > 3
|
||||||
|
let filter = a:4
|
||||||
|
else
|
||||||
|
let filter = ''
|
||||||
|
endif
|
||||||
|
|
||||||
if has_key(s:zen_settings[type], 'indentation')
|
if has_key(s:zen_settings[type], 'indentation')
|
||||||
let indent = s:zen_settings[type].indentation
|
let indent = s:zen_settings[type].indentation
|
||||||
@@ -1030,15 +1035,26 @@ function! s:zen_toString(...)
|
|||||||
let m = 0
|
let m = 0
|
||||||
let str = ''
|
let str = ''
|
||||||
while m < current.multiplier
|
while m < current.multiplier
|
||||||
|
let comment_indent = ''
|
||||||
|
let comment = ''
|
||||||
if len(current.name) && type == 'html'
|
if len(current.name) && type == 'html'
|
||||||
let str .= '<' . current.name
|
if filter == 'c'
|
||||||
|
let comment_indent = substitute(str, '^.*\(\s*\)$', '\1', '')
|
||||||
|
endif
|
||||||
|
let tmp = '<' . current.name
|
||||||
for attr in keys(current.attr)
|
for attr in keys(current.attr)
|
||||||
if current.multiplier > 1 && current.attr[attr] =~ '\$'
|
let val = current.attr[attr]
|
||||||
let str .= ' ' . attr . '="' . substitute(current.attr[attr], '\$', m+1, 'g') . '"'
|
if current.multiplier > 1 && val =~ '\$'
|
||||||
else
|
let val = substitute(val, '\$', m+1, 'g')
|
||||||
let str .= ' ' . attr . '="' . current.attr[attr] . '"'
|
endif
|
||||||
|
let tmp .= ' ' . attr . '="' . val . '"'
|
||||||
|
if filter == 'c'
|
||||||
|
if attr == 'id' | let comment .= '#' . val | endif
|
||||||
|
if attr == 'class' | let comment .= '.' . val | endif
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
if len(comment) > 0 | let tmp = "<!-- " . comment . " -->\n" . comment_indent . tmp | endif
|
||||||
|
let str .= tmp
|
||||||
let inner = current.value[1:-2]
|
let inner = current.value[1:-2]
|
||||||
if stridx(','.s:zen_settings[type].inline_elements.',', ','.current.name.',') != -1
|
if stridx(','.s:zen_settings[type].inline_elements.',', ','.current.name.',') != -1
|
||||||
let child_inline = 1
|
let child_inline = 1
|
||||||
@@ -1046,7 +1062,7 @@ function! s:zen_toString(...)
|
|||||||
let child_inline = 0
|
let child_inline = 0
|
||||||
endif
|
endif
|
||||||
for child in current.child
|
for child in current.child
|
||||||
let inner .= s:zen_toString(child, type, child_inline)
|
let inner .= s:zen_toString(child, type, child_inline, filter)
|
||||||
endfor
|
endfor
|
||||||
if len(current.child)
|
if len(current.child)
|
||||||
if inline == 0
|
if inline == 0
|
||||||
@@ -1060,6 +1076,7 @@ function! s:zen_toString(...)
|
|||||||
else
|
else
|
||||||
let str .= ">" . inner . "</" . current.name . ">"
|
let str .= ">" . inner . "</" . current.name . ">"
|
||||||
endif
|
endif
|
||||||
|
if len(comment) > 0 | let str .= "<!-- /" . comment . " -->\n" . comment_indent | endif
|
||||||
else
|
else
|
||||||
if inline == 0
|
if inline == 0
|
||||||
if stridx(','.s:zen_settings[type].empty_elements.',', ','.current.name.',') != -1
|
if stridx(','.s:zen_settings[type].empty_elements.',', ','.current.name.',') != -1
|
||||||
@@ -1071,6 +1088,7 @@ function! s:zen_toString(...)
|
|||||||
let str .= ">" . inner . "|</" . current.name . ">\n"
|
let str .= ">" . inner . "|</" . current.name . ">\n"
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
if len(comment) > 0 | let str .= "<!-- /" . comment . " -->\n" . comment_indent | endif
|
||||||
else
|
else
|
||||||
if stridx(','.s:zen_settings[type].empty_elements.',', ','.current.name.',') != -1
|
if stridx(','.s:zen_settings[type].empty_elements.',', ','.current.name.',') != -1
|
||||||
let str .= " />"
|
let str .= " />"
|
||||||
@@ -1090,7 +1108,7 @@ function! s:zen_toString(...)
|
|||||||
let inner = ''
|
let inner = ''
|
||||||
if len(current.child)
|
if len(current.child)
|
||||||
for n in current.child
|
for n in current.child
|
||||||
let inner .= s:zen_toString(n, type, inline)
|
let inner .= s:zen_toString(n, type, inline, filter)
|
||||||
endfor
|
endfor
|
||||||
let inner = substitute(inner, "\n", "\n" . indent, 'g')
|
let inner = substitute(inner, "\n", "\n" . indent, 'g')
|
||||||
endif
|
endif
|
||||||
@@ -1111,19 +1129,25 @@ endfunction
|
|||||||
function! s:zen_expandAbbr(mode) range
|
function! s:zen_expandAbbr(mode) range
|
||||||
let type = s:zen_getFileType()
|
let type = s:zen_getFileType()
|
||||||
let expand = ''
|
let expand = ''
|
||||||
|
let filter = ''
|
||||||
|
let line = ''
|
||||||
|
let part = ''
|
||||||
|
let rest = ''
|
||||||
if a:mode == 2
|
if a:mode == 2
|
||||||
let leader = substitute(input('Tag: ', ''), ' ', '', 'g')
|
let leader = substitute(input('Tag: ', ''), '^\s*\(.*\)\s*$', '\1', 'g')
|
||||||
if len(leader) == 0
|
if len(leader) == 0
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
let line = ''
|
let mx = '|\(e\|c\|fc\|xsl\)\s*$'
|
||||||
let part = ''
|
if leader =~ mx
|
||||||
let rest = ''
|
let filter = substitute(matchstr(leader, mx), mx, '\1', '')
|
||||||
|
let leader = substitute(leader, mx, '', '')
|
||||||
|
endif
|
||||||
if leader =~ '\*'
|
if leader =~ '\*'
|
||||||
let query = substitute(leader, '*', '{$line$}*' . (a:lastline - a:firstline + 1), '')
|
let query = substitute(leader, '*', '{$line$}*' . (a:lastline - a:firstline + 1), '')
|
||||||
let items = s:zen_parseIntoTree(query, type).child
|
let items = s:zen_parseIntoTree(query, type).child
|
||||||
for item in items
|
for item in items
|
||||||
let expand .= s:zen_toString(item, type)
|
let expand .= s:zen_toString(item, type, 0, filter)
|
||||||
endfor
|
endfor
|
||||||
let line = getline(a:firstline)
|
let line = getline(a:firstline)
|
||||||
let part = substitute(line, '^\s*', '', '')
|
let part = substitute(line, '^\s*', '', '')
|
||||||
@@ -1132,7 +1156,7 @@ function! s:zen_expandAbbr(mode) range
|
|||||||
let lpart = substitute(lline, '^\s*', '', '')
|
let lpart = substitute(lline, '^\s*', '', '')
|
||||||
let expand = substitute(expand, '\$line\$', lpart, '')
|
let expand = substitute(expand, '\$line\$', lpart, '')
|
||||||
endfor
|
endfor
|
||||||
else
|
elseif len(leader)
|
||||||
let str = ''
|
let str = ''
|
||||||
if a:firstline != a:lastline
|
if a:firstline != a:lastline
|
||||||
let line = getline(a:firstline)
|
let line = getline(a:firstline)
|
||||||
@@ -1146,8 +1170,10 @@ function! s:zen_expandAbbr(mode) range
|
|||||||
let items = s:zen_parseIntoTree(leader . "{" . str . "}", type).child
|
let items = s:zen_parseIntoTree(leader . "{" . str . "}", type).child
|
||||||
endif
|
endif
|
||||||
for item in items
|
for item in items
|
||||||
let expand .= s:zen_toString(item, type)
|
let expand .= s:zen_toString(item, type, 0, filter)
|
||||||
endfor
|
endfor
|
||||||
|
else
|
||||||
|
let expand = join(getline(a:firstline, a:lastline), "\n")
|
||||||
endif
|
endif
|
||||||
silent! exe "normal! gvc"
|
silent! exe "normal! gvc"
|
||||||
else
|
else
|
||||||
@@ -1158,9 +1184,15 @@ function! s:zen_expandAbbr(mode) range
|
|||||||
let part = matchstr(line, '\(\S.*\)$')
|
let part = matchstr(line, '\(\S.*\)$')
|
||||||
endif
|
endif
|
||||||
let rest = getline('.')[col('.')+1:]
|
let rest = getline('.')[col('.')+1:]
|
||||||
let items = s:zen_parseIntoTree(part, type).child
|
let str = part
|
||||||
|
let mx = '|\(e\|c\|fc\|xsl\)\s*$'
|
||||||
|
if str =~ mx
|
||||||
|
let filter = substitute(matchstr(str, mx), mx, '\1', '')
|
||||||
|
let str = substitute(str, mx, '', '')
|
||||||
|
endif
|
||||||
|
let items = s:zen_parseIntoTree(str, type).child
|
||||||
for item in items
|
for item in items
|
||||||
let expand .= s:zen_toString(item, type)
|
let expand .= s:zen_toString(item, type, 0, filter)
|
||||||
endfor
|
endfor
|
||||||
endif
|
endif
|
||||||
if len(expand)
|
if len(expand)
|
||||||
@@ -1185,6 +1217,11 @@ function! s:zen_expandAbbr(mode) range
|
|||||||
endif
|
endif
|
||||||
let expand = substitute(expand, '\n\s*$', '', 'g')
|
let expand = substitute(expand, '\n\s*$', '', 'g')
|
||||||
let expand = line[:-len(part)-1] . substitute(expand, "\n", "\n" . indent, 'g') . rest
|
let expand = line[:-len(part)-1] . substitute(expand, "\n", "\n" . indent, 'g') . rest
|
||||||
|
if filter == 'e'
|
||||||
|
let expand = substitute(expand, '&', '\&', 'g')
|
||||||
|
let expand = substitute(expand, '<', '\<', 'g')
|
||||||
|
let expand = substitute(expand, '>', '\>', 'g')
|
||||||
|
endif
|
||||||
let lines = split(expand, '\n')
|
let lines = split(expand, '\n')
|
||||||
call setline(line('.'), lines[0])
|
call setline(line('.'), lines[0])
|
||||||
if len(lines) > 1
|
if len(lines) > 1
|
||||||
|
|||||||
Reference in New Issue
Block a user