mirror of
https://github.com/mattn/emmet-vim.git
synced 2025-12-14 22:37:07 +08:00
dynamic filter. then, you can customize the filters.
This commit is contained in:
316
zencoding.vim
316
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,16 +1092,175 @@ function! s:zen_parseIntoTree(abbr, type)
|
|||||||
return root
|
return root
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
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 = ""
|
||||||
|
|
||||||
|
let comment_indent = ''
|
||||||
|
let comment = ''
|
||||||
|
if len(current.name) > 0
|
||||||
|
let str .= '%' . current.name
|
||||||
|
let tmp = ''
|
||||||
|
for attr in keys(current.attr)
|
||||||
|
let val = current.attr[attr]
|
||||||
|
if current.multiplier > 1
|
||||||
|
while val =~ '\$[^{]*'
|
||||||
|
let val = substitute(val, '\(\$\+\)\([^{]*\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||||
|
endwhile
|
||||||
|
endif
|
||||||
|
if attr == 'id'
|
||||||
|
let str .= '#' . val
|
||||||
|
elseif attr == 'class'
|
||||||
|
let str .= '.' . substitute(val, ' ', '.', 'g')
|
||||||
|
else
|
||||||
|
if len(tmp) > 0 | let tmp .= ',' | endif
|
||||||
|
let tmp .= ' :' . attr . ' => "' . val . '"'
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
if len(tmp)
|
||||||
|
let str .= '{' . tmp . ' }'
|
||||||
|
endif
|
||||||
|
if stridx(','.settings.html.empty_elements.',', ','.current.name.',') != -1 && len(current.value) == 0
|
||||||
|
let str .= "/"
|
||||||
|
elseif stridx(','.settings.html.block_elements.',', ','.current.name.',') != -1 && (len(current.child) == 0 && len(current.value) == 0)
|
||||||
|
let str .= '<'
|
||||||
|
endif
|
||||||
|
|
||||||
|
let inner = ''
|
||||||
|
if len(current.value) > 0
|
||||||
|
let lines = split(current.value[1:-2], "\n")
|
||||||
|
let str .= " " . lines[0]
|
||||||
|
for line in lines[1:]
|
||||||
|
let str .= " |\n" . line
|
||||||
|
endfor
|
||||||
|
endif
|
||||||
|
if len(current.child) == 1 && len(current.child[0].name) == 0
|
||||||
|
let lines = split(current.child[0].value[1:-2], "\n")
|
||||||
|
let str .= " " . lines[0]
|
||||||
|
for line in lines[1:]
|
||||||
|
let str .= " |\n" . line
|
||||||
|
endfor
|
||||||
|
elseif len(current.child) > 0
|
||||||
|
for child in current.child
|
||||||
|
let inner .= s:zen_toString(child, type, inline, filters)
|
||||||
|
endfor
|
||||||
|
let inner = substitute(inner, "\n", "\n ", 'g')
|
||||||
|
let inner = substitute(inner, "\n $", "", 'g')
|
||||||
|
let str .= "\n " . inner
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
let str .= "\n"
|
||||||
|
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
|
||||||
|
let tmp = '<' . current.name
|
||||||
|
for attr in keys(current.attr)
|
||||||
|
if current.name =~ '^\(xsl:with-param\|xsl:variable\)$' && s:zen_use_filter(filters, 'xsl') && len(current.child) && attr == 'select'
|
||||||
|
continue
|
||||||
|
endif
|
||||||
|
let val = current.attr[attr]
|
||||||
|
if current.multiplier > 1
|
||||||
|
while val =~ '\$\([^{]\|$\)'
|
||||||
|
let val = substitute(val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||||
|
endwhile
|
||||||
|
endif
|
||||||
|
let tmp .= ' ' . attr . '="' . val . '"'
|
||||||
|
if s:zen_use_filter(filters, 'c')
|
||||||
|
if attr == 'id' | let comment .= '#' . val | endif
|
||||||
|
if attr == 'class' | let comment .= '.' . val | endif
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
if len(comment) > 0
|
||||||
|
let tmp = "<!-- " . comment . " -->" . (inline ? "" : "\n") . comment_indent . tmp
|
||||||
|
endif
|
||||||
|
let str .= tmp
|
||||||
|
let inner = current.value[1:-2]
|
||||||
|
if stridx(','.settings.html.inline_elements.',', ','.current.name.',') != -1
|
||||||
|
let child_inline = 1
|
||||||
|
else
|
||||||
|
let child_inline = 0
|
||||||
|
endif
|
||||||
|
for child in current.child
|
||||||
|
let html = s:zen_toString(child, type, child_inline, filters)
|
||||||
|
if child.name == 'br'
|
||||||
|
let inner = substitute(inner, '\n\s*$', '', '')
|
||||||
|
endif
|
||||||
|
let inner .= html
|
||||||
|
endfor
|
||||||
|
if len(current.child) == 1 && current.child[0].name == ''
|
||||||
|
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(','.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"
|
||||||
|
else
|
||||||
|
let str .= ">" . inner . "</" . current.name . ">\n"
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
let str .= ">" . inner . "</" . current.name . ">"
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
if inline == 0
|
||||||
|
if stridx(','.settings.html.empty_elements.',', ','.current.name.',') != -1
|
||||||
|
let str .= " />\n"
|
||||||
|
else
|
||||||
|
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(','.settings.html.empty_elements.',', ','.current.name.',') != -1
|
||||||
|
let str .= " />"
|
||||||
|
else
|
||||||
|
let str .= ">" . inner . '${cursor}</' . current.name . ">"
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
if len(comment) > 0
|
||||||
|
let str .= "<!-- /" . comment . " -->" . (inline ? "" : "\n") . comment_indent
|
||||||
|
endif
|
||||||
|
return str
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:zen_toString(...)
|
function! s:zen_toString(...)
|
||||||
let current = a:1
|
let current = a:1
|
||||||
if a:0 > 1
|
if a:0 > 1
|
||||||
let type = a:2
|
let type = a:2
|
||||||
else
|
else
|
||||||
let type = ''
|
let type = &ft
|
||||||
endif
|
|
||||||
if !has_key(s:zen_settings, type)
|
|
||||||
let type = 'html'
|
|
||||||
endif
|
endif
|
||||||
|
" if !has_key(s:zen_settings, type)
|
||||||
|
" let type = 'html'
|
||||||
|
" endif
|
||||||
if len(type) == 0 | let type = 'html' | endif
|
if len(type) == 0 | let type = 'html' | endif
|
||||||
if a:0 > 2
|
if a:0 > 2
|
||||||
let inline = a:3
|
let inline = a:3
|
||||||
@@ -1118,146 +1277,21 @@ function! s:zen_toString(...)
|
|||||||
let filters = ['html']
|
let filters = ['html']
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if has_key(s:zen_settings[type], 'indentation')
|
if has_key(s:zen_settings, type) && has_key(s:zen_settings[type], 'indentation')
|
||||||
let indent = s:zen_settings[type].indentation
|
let indent = s:zen_settings[type].indentation
|
||||||
else
|
else
|
||||||
let indent = s:zen_settings.indentation
|
let indent = s:zen_settings.indentation
|
||||||
endif
|
endif
|
||||||
let m = 0
|
let itemno = 0
|
||||||
let str = ''
|
let str = ''
|
||||||
while m < current.multiplier
|
while itemno < current.multiplier
|
||||||
let comment_indent = ''
|
if len(current.name)
|
||||||
let comment = ''
|
if exists('*g:zen_toString_'.type)
|
||||||
if s:zen_use_filter(filters, 'haml')
|
let str .= function('g:zen_toString_'.type)(s:zen_settings, current, type, inline, filters, itemno, indent)
|
||||||
if len(current.name) > 0
|
elseif s:zen_use_filter(filters, 'haml')
|
||||||
let str .= '%' . current.name
|
let str .= s:zen_toString_haml(s:zen_settings, current, type, inline, filters, itemno, indent)
|
||||||
let tmp = ''
|
elseif s:zen_use_filter(filters, 'html')
|
||||||
for attr in keys(current.attr)
|
let str .= s:zen_toString_html(s:zen_settings, current, type, inline, filters, itemno, indent)
|
||||||
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')
|
|
||||||
endwhile
|
|
||||||
endif
|
|
||||||
if attr == 'id'
|
|
||||||
let str .= '#' . val
|
|
||||||
elseif attr == 'class'
|
|
||||||
let str .= '.' . substitute(val, ' ', '.', 'g')
|
|
||||||
else
|
|
||||||
if len(tmp) > 0 | let tmp .= ',' | endif
|
|
||||||
let tmp .= ' :' . attr . ' => "' . val . '"'
|
|
||||||
endif
|
|
||||||
endfor
|
|
||||||
if len(tmp)
|
|
||||||
let str .= '{' . tmp . ' }'
|
|
||||||
endif
|
|
||||||
if stridx(','.s:zen_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)
|
|
||||||
let str .= '<'
|
|
||||||
endif
|
|
||||||
|
|
||||||
let inner = ''
|
|
||||||
if len(current.value) > 0
|
|
||||||
let lines = split(current.value[1:-2], "\n")
|
|
||||||
let str .= " " . lines[0]
|
|
||||||
for line in lines[1:]
|
|
||||||
let str .= " |\n" . line
|
|
||||||
endfor
|
|
||||||
endif
|
|
||||||
if len(current.child) == 1 && len(current.child[0].name) == 0
|
|
||||||
let lines = split(current.child[0].value[1:-2], "\n")
|
|
||||||
let str .= " " . lines[0]
|
|
||||||
for line in lines[1:]
|
|
||||||
let str .= " |\n" . line
|
|
||||||
endfor
|
|
||||||
elseif len(current.child) > 0
|
|
||||||
for child in current.child
|
|
||||||
let inner .= s:zen_toString(child, type, inline, filters)
|
|
||||||
endfor
|
|
||||||
let inner = substitute(inner, "\n", "\n ", 'g')
|
|
||||||
let inner = substitute(inner, "\n $", "", 'g')
|
|
||||||
let str .= "\n " . inner
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
let str .= "\n"
|
|
||||||
elseif len(current.name) && s:zen_use_filter(filters, 'html')
|
|
||||||
if s:zen_use_filter(filters, 'c')
|
|
||||||
let comment_indent = substitute(str, '^.*\(\s*\)$', '\1', '')
|
|
||||||
endif
|
|
||||||
let tmp = '<' . current.name
|
|
||||||
for attr in keys(current.attr)
|
|
||||||
if current.name =~ '^\(xsl:with-param\|xsl:variable\)$' && s:zen_use_filter(filters, 'xsl') && len(current.child) && attr == 'select'
|
|
||||||
continue
|
|
||||||
endif
|
|
||||||
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')
|
|
||||||
endwhile
|
|
||||||
endif
|
|
||||||
let tmp .= ' ' . attr . '="' . val . '"'
|
|
||||||
if s:zen_use_filter(filters, 'c')
|
|
||||||
if attr == 'id' | let comment .= '#' . val | endif
|
|
||||||
if attr == 'class' | let comment .= '.' . val | endif
|
|
||||||
endif
|
|
||||||
endfor
|
|
||||||
if len(comment) > 0
|
|
||||||
let tmp = "<!-- " . comment . " -->" . (inline ? "" : "\n") . comment_indent . tmp
|
|
||||||
endif
|
|
||||||
let str .= tmp
|
|
||||||
let inner = current.value[1:-2]
|
|
||||||
if stridx(','.s:zen_settings.html.inline_elements.',', ','.current.name.',') != -1
|
|
||||||
let child_inline = 1
|
|
||||||
else
|
|
||||||
let child_inline = 0
|
|
||||||
endif
|
|
||||||
for child in current.child
|
|
||||||
let html = s:zen_toString(child, type, child_inline, filters)
|
|
||||||
if child.name == 'br'
|
|
||||||
let inner = substitute(inner, '\n\s*$', '', '')
|
|
||||||
endif
|
|
||||||
let inner .= html
|
|
||||||
endfor
|
|
||||||
if len(current.child) == 1 && current.child[0].name == ''
|
|
||||||
if stridx(','.s:zen_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
|
|
||||||
let inner = substitute(inner, "\n", "\n" . indent, 'g')
|
|
||||||
let inner = substitute(inner, indent . "$", "", 'g')
|
|
||||||
let str .= ">\n" . indent . inner . "</" . current.name . ">\n"
|
|
||||||
else
|
|
||||||
let str .= ">" . inner . "</" . current.name . ">\n"
|
|
||||||
endif
|
|
||||||
else
|
|
||||||
let str .= ">" . inner . "</" . current.name . ">"
|
|
||||||
endif
|
|
||||||
else
|
|
||||||
if inline == 0
|
|
||||||
if stridx(','.s:zen_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)
|
|
||||||
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
|
|
||||||
let str .= " />"
|
|
||||||
else
|
|
||||||
let str .= ">" . inner . '${cursor}</' . current.name . ">"
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
if len(comment) > 0
|
|
||||||
let str .= "<!-- /" . comment . " -->" . (inline ? "" : "\n") . comment_indent
|
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
if len(current.snippet) > 0
|
if len(current.snippet) > 0
|
||||||
@@ -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