mirror of
https://github.com/mattn/emmet-vim.git
synced 2025-12-14 14:27:06 +08:00
dynamic filter. then, you can customize the filters.
This commit is contained in:
128
zencoding.vim
128
zencoding.vim
@@ -1,7 +1,7 @@
|
|||||||
"=============================================================================
|
"=============================================================================
|
||||||
" File: zencoding.vim
|
" File: zencoding.vim
|
||||||
" Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
|
" Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
|
||||||
" Last Change: 13-May-2010.
|
" Last Change: 21-May-2010.
|
||||||
" Version: 0.40
|
" Version: 0.40
|
||||||
" WebPage: http://github.com/mattn/zencoding-vim
|
" WebPage: http://github.com/mattn/zencoding-vim
|
||||||
" Description: vim plugins for HTML and CSS hi-speed coding.
|
" Description: vim plugins for HTML and CSS hi-speed coding.
|
||||||
@@ -1092,43 +1092,18 @@ function! s:zen_parseIntoTree(abbr, type)
|
|||||||
return root
|
return root
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:zen_toString(...)
|
function! s:zen_toString_haml(settings, current, type, inline, filters, itemno, indent)
|
||||||
let current = a:1
|
let settings = a:settings
|
||||||
if a:0 > 1
|
let current = a:current
|
||||||
let type = a:2
|
let type = a:type
|
||||||
else
|
let inline = a:inline
|
||||||
let type = ''
|
let filters = a:filters
|
||||||
endif
|
let itemno = a:itemno
|
||||||
if !has_key(s:zen_settings, type)
|
let indent = a:indent
|
||||||
let type = 'html'
|
let str = ""
|
||||||
endif
|
|
||||||
if len(type) == 0 | let type = 'html' | endif
|
|
||||||
if a:0 > 2
|
|
||||||
let inline = a:3
|
|
||||||
else
|
|
||||||
let inline = 0
|
|
||||||
endif
|
|
||||||
if a:0 > 3
|
|
||||||
if type(a:4) == 1
|
|
||||||
let filters = split(a:4, '\s*,\s*')
|
|
||||||
else
|
|
||||||
let filters = a:4
|
|
||||||
endif
|
|
||||||
else
|
|
||||||
let filters = ['html']
|
|
||||||
endif
|
|
||||||
|
|
||||||
if has_key(s:zen_settings[type], 'indentation')
|
|
||||||
let indent = s:zen_settings[type].indentation
|
|
||||||
else
|
|
||||||
let indent = s:zen_settings.indentation
|
|
||||||
endif
|
|
||||||
let m = 0
|
|
||||||
let str = ''
|
|
||||||
while m < current.multiplier
|
|
||||||
let comment_indent = ''
|
let comment_indent = ''
|
||||||
let comment = ''
|
let comment = ''
|
||||||
if s:zen_use_filter(filters, 'haml')
|
|
||||||
if len(current.name) > 0
|
if len(current.name) > 0
|
||||||
let str .= '%' . current.name
|
let str .= '%' . current.name
|
||||||
let tmp = ''
|
let tmp = ''
|
||||||
@@ -1136,7 +1111,7 @@ function! s:zen_toString(...)
|
|||||||
let val = current.attr[attr]
|
let val = current.attr[attr]
|
||||||
if current.multiplier > 1
|
if current.multiplier > 1
|
||||||
while val =~ '\$[^{]*'
|
while val =~ '\$[^{]*'
|
||||||
let val = substitute(val, '\(\$\+\)\([^{]*\)', '\=printf("%0".len(submatch(1))."d", m+1).submatch(2)', 'g')
|
let val = substitute(val, '\(\$\+\)\([^{]*\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||||
endwhile
|
endwhile
|
||||||
endif
|
endif
|
||||||
if attr == 'id'
|
if attr == 'id'
|
||||||
@@ -1151,9 +1126,9 @@ function! s:zen_toString(...)
|
|||||||
if len(tmp)
|
if len(tmp)
|
||||||
let str .= '{' . tmp . ' }'
|
let str .= '{' . tmp . ' }'
|
||||||
endif
|
endif
|
||||||
if stridx(','.s:zen_settings.html.empty_elements.',', ','.current.name.',') != -1 && len(current.value) == 0
|
if stridx(','.settings.html.empty_elements.',', ','.current.name.',') != -1 && len(current.value) == 0
|
||||||
let str .= "/"
|
let str .= "/"
|
||||||
elseif stridx(','.s:zen_settings.html.block_elements.',', ','.current.name.',') != -1 && (len(current.child) == 0 && len(current.value) == 0)
|
elseif stridx(','.settings.html.block_elements.',', ','.current.name.',') != -1 && (len(current.child) == 0 && len(current.value) == 0)
|
||||||
let str .= '<'
|
let str .= '<'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@@ -1181,7 +1156,21 @@ function! s:zen_toString(...)
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
let str .= "\n"
|
let str .= "\n"
|
||||||
elseif len(current.name) && s:zen_use_filter(filters, 'html')
|
return str
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:zen_toString_html(settings, current, type, inline, filters, itemno, indent)
|
||||||
|
let settings = a:settings
|
||||||
|
let current = a:current
|
||||||
|
let type = a:type
|
||||||
|
let inline = a:inline
|
||||||
|
let filters = a:filters
|
||||||
|
let itemno = a:itemno
|
||||||
|
let indent = a:indent
|
||||||
|
let str = ""
|
||||||
|
|
||||||
|
let comment_indent = ''
|
||||||
|
let comment = ''
|
||||||
if s:zen_use_filter(filters, 'c')
|
if s:zen_use_filter(filters, 'c')
|
||||||
let comment_indent = substitute(str, '^.*\(\s*\)$', '\1', '')
|
let comment_indent = substitute(str, '^.*\(\s*\)$', '\1', '')
|
||||||
endif
|
endif
|
||||||
@@ -1193,7 +1182,7 @@ function! s:zen_toString(...)
|
|||||||
let val = current.attr[attr]
|
let val = current.attr[attr]
|
||||||
if current.multiplier > 1
|
if current.multiplier > 1
|
||||||
while val =~ '\$\([^{]\|$\)'
|
while val =~ '\$\([^{]\|$\)'
|
||||||
let val = substitute(val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", m+1).submatch(2)', 'g')
|
let val = substitute(val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||||
endwhile
|
endwhile
|
||||||
endif
|
endif
|
||||||
let tmp .= ' ' . attr . '="' . val . '"'
|
let tmp .= ' ' . attr . '="' . val . '"'
|
||||||
@@ -1207,7 +1196,7 @@ function! s:zen_toString(...)
|
|||||||
endif
|
endif
|
||||||
let str .= tmp
|
let str .= tmp
|
||||||
let inner = current.value[1:-2]
|
let inner = current.value[1:-2]
|
||||||
if stridx(','.s:zen_settings.html.inline_elements.',', ','.current.name.',') != -1
|
if stridx(','.settings.html.inline_elements.',', ','.current.name.',') != -1
|
||||||
let child_inline = 1
|
let child_inline = 1
|
||||||
else
|
else
|
||||||
let child_inline = 0
|
let child_inline = 0
|
||||||
@@ -1220,14 +1209,14 @@ function! s:zen_toString(...)
|
|||||||
let inner .= html
|
let inner .= html
|
||||||
endfor
|
endfor
|
||||||
if len(current.child) == 1 && current.child[0].name == ''
|
if len(current.child) == 1 && current.child[0].name == ''
|
||||||
if stridx(','.s:zen_settings.html.inline_elements.',', ','.current.name.',') == -1
|
if stridx(','.settings.html.inline_elements.',', ','.current.name.',') == -1
|
||||||
let str .= ">" . inner . "</" . current.name . ">\n"
|
let str .= ">" . inner . "</" . current.name . ">\n"
|
||||||
else
|
else
|
||||||
let str .= ">" . inner . "</" . current.name . ">"
|
let str .= ">" . inner . "</" . current.name . ">"
|
||||||
endif
|
endif
|
||||||
elseif len(current.child)
|
elseif len(current.child)
|
||||||
if inline == 0
|
if inline == 0
|
||||||
if stridx(','.s:zen_settings.html.inline_elements.',', ','.current.name.',') == -1
|
if stridx(','.settings.html.inline_elements.',', ','.current.name.',') == -1
|
||||||
let inner = substitute(inner, "\n", "\n" . indent, 'g')
|
let inner = substitute(inner, "\n", "\n" . indent, 'g')
|
||||||
let inner = substitute(inner, indent . "$", "", 'g')
|
let inner = substitute(inner, indent . "$", "", 'g')
|
||||||
let str .= ">\n" . indent . inner . "</" . current.name . ">\n"
|
let str .= ">\n" . indent . inner . "</" . current.name . ">\n"
|
||||||
@@ -1239,17 +1228,17 @@ function! s:zen_toString(...)
|
|||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
if inline == 0
|
if inline == 0
|
||||||
if stridx(','.s:zen_settings.html.empty_elements.',', ','.current.name.',') != -1
|
if stridx(','.settings.html.empty_elements.',', ','.current.name.',') != -1
|
||||||
let str .= " />\n"
|
let str .= " />\n"
|
||||||
else
|
else
|
||||||
if stridx(','.s:zen_settings.html.inline_elements.',', ','.current.name.',') == -1 && len(current.child)
|
if stridx(','.settings.html.inline_elements.',', ','.current.name.',') == -1 && len(current.child)
|
||||||
let str .= ">\n" . inner . '${cursor}</' . current.name . ">\n"
|
let str .= ">\n" . inner . '${cursor}</' . current.name . ">\n"
|
||||||
else
|
else
|
||||||
let str .= ">" . inner . '${cursor}</' . current.name . ">\n"
|
let str .= ">" . inner . '${cursor}</' . current.name . ">\n"
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
if stridx(','.s:zen_settings.html.empty_elements.',', ','.current.name.',') != -1
|
if stridx(','.settings.html.empty_elements.',', ','.current.name.',') != -1
|
||||||
let str .= " />"
|
let str .= " />"
|
||||||
else
|
else
|
||||||
let str .= ">" . inner . '${cursor}</' . current.name . ">"
|
let str .= ">" . inner . '${cursor}</' . current.name . ">"
|
||||||
@@ -1259,6 +1248,51 @@ function! s:zen_toString(...)
|
|||||||
if len(comment) > 0
|
if len(comment) > 0
|
||||||
let str .= "<!-- /" . comment . " -->" . (inline ? "" : "\n") . comment_indent
|
let str .= "<!-- /" . comment . " -->" . (inline ? "" : "\n") . comment_indent
|
||||||
endif
|
endif
|
||||||
|
return str
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:zen_toString(...)
|
||||||
|
let current = a:1
|
||||||
|
if a:0 > 1
|
||||||
|
let type = a:2
|
||||||
|
else
|
||||||
|
let type = &ft
|
||||||
|
endif
|
||||||
|
" if !has_key(s:zen_settings, type)
|
||||||
|
" let type = 'html'
|
||||||
|
" endif
|
||||||
|
if len(type) == 0 | let type = 'html' | endif
|
||||||
|
if a:0 > 2
|
||||||
|
let inline = a:3
|
||||||
|
else
|
||||||
|
let inline = 0
|
||||||
|
endif
|
||||||
|
if a:0 > 3
|
||||||
|
if type(a:4) == 1
|
||||||
|
let filters = split(a:4, '\s*,\s*')
|
||||||
|
else
|
||||||
|
let filters = a:4
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
let filters = ['html']
|
||||||
|
endif
|
||||||
|
|
||||||
|
if has_key(s:zen_settings, type) && has_key(s:zen_settings[type], 'indentation')
|
||||||
|
let indent = s:zen_settings[type].indentation
|
||||||
|
else
|
||||||
|
let indent = s:zen_settings.indentation
|
||||||
|
endif
|
||||||
|
let itemno = 0
|
||||||
|
let str = ''
|
||||||
|
while itemno < current.multiplier
|
||||||
|
if len(current.name)
|
||||||
|
if exists('*g:zen_toString_'.type)
|
||||||
|
let str .= function('g:zen_toString_'.type)(s:zen_settings, current, type, inline, filters, itemno, indent)
|
||||||
|
elseif s:zen_use_filter(filters, 'haml')
|
||||||
|
let str .= s:zen_toString_haml(s:zen_settings, current, type, inline, filters, itemno, indent)
|
||||||
|
elseif s:zen_use_filter(filters, 'html')
|
||||||
|
let str .= s:zen_toString_html(s:zen_settings, current, type, inline, filters, itemno, indent)
|
||||||
|
endif
|
||||||
else
|
else
|
||||||
if len(current.snippet) > 0
|
if len(current.snippet) > 0
|
||||||
let tmp = substitute(current.snippet, '|', '${cursor}', 'g')
|
let tmp = substitute(current.snippet, '|', '${cursor}', 'g')
|
||||||
@@ -1283,7 +1317,7 @@ function! s:zen_toString(...)
|
|||||||
endif
|
endif
|
||||||
let str = substitute(str, '\${child}', inner, '')
|
let str = substitute(str, '\${child}', inner, '')
|
||||||
endif
|
endif
|
||||||
let m = m + 1
|
let itemno = itemno + 1
|
||||||
endwhile
|
endwhile
|
||||||
if s:zen_use_filter(filters, 'e')
|
if s:zen_use_filter(filters, 'e')
|
||||||
let str = substitute(str, '&', '\&', 'g')
|
let str = substitute(str, '&', '\&', 'g')
|
||||||
|
|||||||
Reference in New Issue
Block a user