mirror of
https://github.com/mattn/emmet-vim.git
synced 2025-12-13 14:01:52 +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
|
||||
" Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
|
||||
" Last Change: 13-May-2010.
|
||||
" Last Change: 21-May-2010.
|
||||
" Version: 0.40
|
||||
" WebPage: http://github.com/mattn/zencoding-vim
|
||||
" Description: vim plugins for HTML and CSS hi-speed coding.
|
||||
@@ -1092,43 +1092,18 @@ function! s:zen_parseIntoTree(abbr, type)
|
||||
return root
|
||||
endfunction
|
||||
|
||||
function! s:zen_toString(...)
|
||||
let current = a:1
|
||||
if a:0 > 1
|
||||
let type = a:2
|
||||
else
|
||||
let type = ''
|
||||
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
|
||||
function! s:zen_toString_haml(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 = ""
|
||||
|
||||
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 = ''
|
||||
if s:zen_use_filter(filters, 'haml')
|
||||
if len(current.name) > 0
|
||||
let str .= '%' . current.name
|
||||
let tmp = ''
|
||||
@@ -1136,7 +1111,7 @@ function! s:zen_toString(...)
|
||||
let val = current.attr[attr]
|
||||
if current.multiplier > 1
|
||||
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
|
||||
endif
|
||||
if attr == 'id'
|
||||
@@ -1151,9 +1126,9 @@ function! s:zen_toString(...)
|
||||
if len(tmp)
|
||||
let str .= '{' . tmp . ' }'
|
||||
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 .= "/"
|
||||
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 .= '<'
|
||||
endif
|
||||
|
||||
@@ -1181,7 +1156,21 @@ function! s:zen_toString(...)
|
||||
endif
|
||||
endif
|
||||
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')
|
||||
let comment_indent = substitute(str, '^.*\(\s*\)$', '\1', '')
|
||||
endif
|
||||
@@ -1193,7 +1182,7 @@ function! s:zen_toString(...)
|
||||
let val = current.attr[attr]
|
||||
if current.multiplier > 1
|
||||
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
|
||||
endif
|
||||
let tmp .= ' ' . attr . '="' . val . '"'
|
||||
@@ -1207,7 +1196,7 @@ function! s:zen_toString(...)
|
||||
endif
|
||||
let str .= tmp
|
||||
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
|
||||
else
|
||||
let child_inline = 0
|
||||
@@ -1220,14 +1209,14 @@ function! s:zen_toString(...)
|
||||
let inner .= html
|
||||
endfor
|
||||
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"
|
||||
else
|
||||
let str .= ">" . inner . "</" . current.name . ">"
|
||||
endif
|
||||
elseif len(current.child)
|
||||
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, indent . "$", "", 'g')
|
||||
let str .= ">\n" . indent . inner . "</" . current.name . ">\n"
|
||||
@@ -1239,17 +1228,17 @@ function! s:zen_toString(...)
|
||||
endif
|
||||
else
|
||||
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"
|
||||
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"
|
||||
else
|
||||
let str .= ">" . inner . '${cursor}</' . current.name . ">\n"
|
||||
endif
|
||||
endif
|
||||
else
|
||||
if stridx(','.s:zen_settings.html.empty_elements.',', ','.current.name.',') != -1
|
||||
if stridx(','.settings.html.empty_elements.',', ','.current.name.',') != -1
|
||||
let str .= " />"
|
||||
else
|
||||
let str .= ">" . inner . '${cursor}</' . current.name . ">"
|
||||
@@ -1259,6 +1248,51 @@ function! s:zen_toString(...)
|
||||
if len(comment) > 0
|
||||
let str .= "<!-- /" . comment . " -->" . (inline ? "" : "\n") . comment_indent
|
||||
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
|
||||
if len(current.snippet) > 0
|
||||
let tmp = substitute(current.snippet, '|', '${cursor}', 'g')
|
||||
@@ -1283,7 +1317,7 @@ function! s:zen_toString(...)
|
||||
endif
|
||||
let str = substitute(str, '\${child}', inner, '')
|
||||
endif
|
||||
let m = m + 1
|
||||
let itemno = itemno + 1
|
||||
endwhile
|
||||
if s:zen_use_filter(filters, 'e')
|
||||
let str = substitute(str, '&', '\&', 'g')
|
||||
|
||||
Reference in New Issue
Block a user