mirror of
https://github.com/mattn/emmet-vim.git
synced 2025-12-07 03:04:27 +08:00
new style formatter.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
"=============================================================================
|
"=============================================================================
|
||||||
" zencoding.vim
|
" zencoding.vim
|
||||||
" Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
|
" Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
|
||||||
" Last Change: 07-Jun-2012.
|
" Last Change: 10-Jun-2012.
|
||||||
|
|
||||||
let s:save_cpo = &cpo
|
let s:save_cpo = &cpo
|
||||||
set cpo&vim
|
set cpo&vim
|
||||||
@@ -1284,7 +1284,7 @@ let s:zen_settings = {
|
|||||||
\ 'optg': 'optgroup>option'
|
\ 'optg': 'optgroup>option'
|
||||||
\ },
|
\ },
|
||||||
\ 'empty_elements': 'area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed,keygen,command',
|
\ 'empty_elements': 'area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed,keygen,command',
|
||||||
\ 'block_elements': 'address,applet,blockquote,button,center,dd,del,dir,div,dl,dt,fieldset,form,frameset,hr,iframe,ins,isindex,link,map,menu,noframes,noscript,object,ol,p,pre,script,table,tbody,td,tfoot,th,thead,tr,ul,h1,h2,h3,h4,h5,h6,style',
|
\ 'block_elements': 'address,applet,blockquote,button,center,dd,del,dir,div,dl,dt,fieldset,form,frameset,hr,iframe,ins,isindex,li,link,map,menu,noframes,noscript,object,ol,p,pre,script,table,tbody,td,tfoot,th,thead,tr,ul,h1,h2,h3,h4,h5,h6,style',
|
||||||
\ 'inline_elements': 'a,abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,script,small,span,strike,strong,sub,sup,textarea,tt,u,var',
|
\ 'inline_elements': 'a,abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,script,small,span,strike,strong,sub,sup,textarea,tt,u,var',
|
||||||
\ },
|
\ },
|
||||||
\ 'xsl': {
|
\ 'xsl': {
|
||||||
|
|||||||
@@ -283,7 +283,6 @@ function! zencoding#lang#html#toString(settings, current, type, inline, filters,
|
|||||||
let filters = a:filters
|
let filters = a:filters
|
||||||
let itemno = a:itemno
|
let itemno = a:itemno
|
||||||
let indent = a:indent
|
let indent = a:indent
|
||||||
let str = ""
|
|
||||||
|
|
||||||
if zencoding#useFilter(filters, 'haml')
|
if zencoding#useFilter(filters, 'haml')
|
||||||
return zencoding#lang#haml#toString(settings, current, type, inline, filters, itemno, indent)
|
return zencoding#lang#haml#toString(settings, current, type, inline, filters, itemno, indent)
|
||||||
@@ -294,96 +293,55 @@ function! zencoding#lang#html#toString(settings, current, type, inline, filters,
|
|||||||
|
|
||||||
let comment = ''
|
let comment = ''
|
||||||
let current_name = current.name
|
let current_name = current.name
|
||||||
let current_name = substitute(current.name, '\$$', itemno+1, '')
|
let current_name = substitute(current_name, '\$$', itemno+1, '')
|
||||||
|
|
||||||
if !empty(current.parent) && len(current.parent.name) > 0 && current.multiplier > 0 && stridx(','.settings.html.inline_elements.',', ','.current_name.',') == -1
|
let str = ''
|
||||||
if current.parent.multiplier > 0
|
let str .= '<' . current_name
|
||||||
let str .= "\n"
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
let tmp = '<' . current_name
|
|
||||||
for attr in keys(current.attr)
|
for attr in keys(current.attr)
|
||||||
if current_name =~ '^\(xsl:with-param\|xsl:variable\)$' && zencoding#useFilter(filters, 'xsl') && len(current.child) && attr == 'select'
|
|
||||||
continue
|
|
||||||
endif
|
|
||||||
let val = current.attr[attr]
|
let val = current.attr[attr]
|
||||||
while val =~ '\$\([^#{]\|$\)'
|
while val =~ '\$\([^#{]\|$\)'
|
||||||
let val = substitute(val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
let val = substitute(val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||||
endwhile
|
endwhile
|
||||||
let attr = substitute(attr, '\$$', itemno+1, '')
|
let attr = substitute(attr, '\$$', itemno+1, '')
|
||||||
let tmp .= ' ' . attr . '="' . val . '"'
|
let str .= ' ' . attr . '="' . val . '"'
|
||||||
if zencoding#useFilter(filters, 'c')
|
if zencoding#useFilter(filters, 'c')
|
||||||
if attr == 'id' | let comment .= '#' . val | endif
|
if attr == 'id' | let comment .= '#' . val | endif
|
||||||
if attr == 'class' | let comment .= '.' . val | endif
|
if attr == 'class' | let comment .= '.' . val | endif
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
if len(comment) > 0
|
if len(comment) > 0
|
||||||
let tmp = "<!-- " . comment . " -->" . (inline ? "" : "\n") . tmp
|
let str = "<!-- " . comment . " -->\n" . str
|
||||||
endif
|
endif
|
||||||
let str .= tmp
|
if stridx(','.settings.html.empty_elements.',', ','.current_name.',') != -1
|
||||||
let inner = current.value[1:-2]
|
let str .= " />"
|
||||||
if stridx(','.settings.html.inline_elements.',', ','.current_name.',') != -1
|
|
||||||
let child_inline = 1
|
|
||||||
else
|
else
|
||||||
let child_inline = 0
|
let str .= ">"
|
||||||
endif
|
let str .= current.value[1:-2]
|
||||||
for child in current.child
|
for n in range(len(current.child))
|
||||||
let html = zencoding#toString(child, type, child_inline, filters)
|
let child = current.child[n]
|
||||||
if child.name == 'br'
|
if len(current.child) > 0 && stridx(','.settings.html.inline_elements.',', ','.current_name.',') == -1
|
||||||
let inner = substitute(inner, '\n\s*$', '', '')
|
if len(current.child) > 1 || stridx(','.settings.html.inline_elements.',', ','.child.name.',') == -1
|
||||||
endif
|
let str .= "\n" . indent
|
||||||
let html = substitute(html, '^\n', '', 'g')
|
|
||||||
let inner .= html
|
|
||||||
endfor
|
|
||||||
if len(current.child) == 1
|
|
||||||
if len(current.child[0].name) > 0 && stridx(','.settings.html.inline_elements.',', ','.current.child[0].name.',') == -1
|
|
||||||
let inner = substitute(inner, "\n", "\n" . indent, 'g')
|
|
||||||
let inner = substitute(inner, indent . "$", "", 'g')
|
|
||||||
let str .= ">\n" . indent . inner . "</" . current_name . ">"
|
|
||||||
else
|
|
||||||
let str .= ">" . inner . "</" . current_name . ">"
|
|
||||||
endif
|
|
||||||
elseif len(current.child)
|
|
||||||
if inline == 0
|
|
||||||
if stridx(','.settings.html.inline_elements.',', ','.current_name.',') == -1
|
|
||||||
if inner =~ "\n$"
|
|
||||||
let inner = substitute(inner, "\n", "\n" . indent, 'g')
|
|
||||||
let inner = substitute(inner, indent . "$", "", 'g')
|
|
||||||
let str .= ">\n" . indent . inner . "</" . current_name . ">"
|
|
||||||
else
|
|
||||||
let str .= ">\n" . indent . inner . indent . "\n</" . current_name . ">"
|
|
||||||
endif
|
endif
|
||||||
else
|
|
||||||
let str .= ">" . inner . "</" . current_name . ">"
|
|
||||||
endif
|
endif
|
||||||
else
|
let inner = zencoding#toString(child, type, 0, filters)
|
||||||
let str .= ">" . inner . "</" . current_name . ">"
|
let inner = substitute(inner, "\n", "\n" . indent, 'g')
|
||||||
endif
|
let inner = substitute(inner, "\n" . indent . '$', '', 'g')
|
||||||
else
|
let str .= inner
|
||||||
if inline == 0
|
endfor
|
||||||
if stridx(','.settings.html.empty_elements.',', ','.current_name.',') != -1
|
if len(current.child) > 0 && stridx(','.settings.html.inline_elements.',', ','.current_name.',') == -1
|
||||||
let str .= " />"
|
if len(current.child) > 1 || (len(current.child) == 1 && stridx(','.settings.html.inline_elements.',', ','.current.child[0].name.',') == -1)
|
||||||
else
|
let str .= "\n"
|
||||||
let str .= ">" . inner . '${cursor}</' . current_name . ">"
|
|
||||||
endif
|
|
||||||
else
|
|
||||||
if stridx(','.settings.html.empty_elements.',', ','.current_name.',') != -1
|
|
||||||
let str .= " />"
|
|
||||||
else
|
|
||||||
let str .= ">" . inner . '${cursor}</' . current_name . ">"
|
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
let str .= "</" . current_name . ">"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if len(comment) > 0
|
if len(comment) > 0
|
||||||
let str .= "\n<!-- /" . comment . " -->" . (inline ? "" : "\n")
|
let str .= "\n<!-- /" . comment . " -->"
|
||||||
endif
|
endif
|
||||||
|
if (current.multiplier > 0 && !empty(current.parent) && len(current.parent.child) > 1)|| stridx(','.settings.html.block_elements.',', ','.current_name.',') != -1
|
||||||
if !empty(current.parent) && len(current.parent.name) == 0 || (current.multiplier > 0 && current.multiplier == itemno+1 && stridx(','.settings.html.inline_elements.',', ','.current_name.',') == -1)
|
|
||||||
let str .= "\n"
|
let str .= "\n"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return str
|
return str
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user