mirror of
https://github.com/mattn/emmet-vim.git
synced 2025-12-07 19:24:27 +08:00
separate files.
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: 21-May-2012.
|
" Last Change: 23-May-2012.
|
||||||
|
|
||||||
let s:save_cpo = &cpo
|
let s:save_cpo = &cpo
|
||||||
set cpo&vim
|
set cpo&vim
|
||||||
@@ -14,7 +14,7 @@ function! s:zen_getExpandos(type, key)
|
|||||||
return a:key
|
return a:key
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:zen_useFilter(filters, filter)
|
function! zencoding#useFilter(filters, filter)
|
||||||
for f in a:filters
|
for f in a:filters
|
||||||
if f == a:filter
|
if f == a:filter
|
||||||
return 1
|
return 1
|
||||||
@@ -354,174 +354,7 @@ function! s:zen_mergeConfig(lhs, rhs)
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:zen_toString_haml(settings, current, type, inline, filters, itemno, indent)
|
function! zencoding#toString(...)
|
||||||
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 = ''
|
|
||||||
let current_name = current.name
|
|
||||||
let current_name = substitute(current.name, '\$$', itemno+1, '')
|
|
||||||
if len(current.name) > 0
|
|
||||||
let str .= '%' . current_name
|
|
||||||
let tmp = ''
|
|
||||||
for attr in keys(current.attr)
|
|
||||||
let val = current.attr[attr]
|
|
||||||
while val =~ '\$\([^#{]\|$\)'
|
|
||||||
let val = substitute(val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
|
||||||
endwhile
|
|
||||||
let attr = substitute(attr, '\$$', itemno+1, '')
|
|
||||||
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 .= "/"
|
|
||||||
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_css(settings, current, type, inline, filters, itemno, indent)
|
|
||||||
return ''
|
|
||||||
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_useFilter(filters, 'c')
|
|
||||||
let comment_indent = substitute(str, '^.*\(\s*\)$', '\1', '')
|
|
||||||
endif
|
|
||||||
let current_name = current.name
|
|
||||||
let current_name = substitute(current.name, '\$$', itemno+1, '')
|
|
||||||
let tmp = '<' . current_name
|
|
||||||
for attr in keys(current.attr)
|
|
||||||
if current_name =~ '^\(xsl:with-param\|xsl:variable\)$' && s:zen_useFilter(filters, 'xsl') && len(current.child) && attr == 'select'
|
|
||||||
continue
|
|
||||||
endif
|
|
||||||
let val = current.attr[attr]
|
|
||||||
while val =~ '\$\([^#{]\|$\)'
|
|
||||||
let val = substitute(val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
|
||||||
endwhile
|
|
||||||
let attr = substitute(attr, '\$$', itemno+1, '')
|
|
||||||
let tmp .= ' ' . attr . '="' . val . '"'
|
|
||||||
if s:zen_useFilter(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
|
|
||||||
if inner =~ "\n$"
|
|
||||||
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 .= ">\n" . indent . inner . indent . "\n</" . current_name . ">\n"
|
|
||||||
endif
|
|
||||||
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(...)
|
|
||||||
let current = a:1
|
let current = a:1
|
||||||
if a:0 > 1
|
if a:0 > 1
|
||||||
let type = a:2
|
let type = a:2
|
||||||
@@ -558,14 +391,14 @@ function! s:zen_toString(...)
|
|||||||
while itemno < current.multiplier
|
while itemno < current.multiplier
|
||||||
if len(current.name)
|
if len(current.name)
|
||||||
let inner = ''
|
let inner = ''
|
||||||
if exists('*g:zen_toString_'.type)
|
if globpath(&rtp, 'autoload/zencoding/'.type.'.vim')
|
||||||
let inner = function('g:zen_toString_'.type)(s:zen_settings, current, type, inline, filters, itemno, indent)
|
let inner = function('g:zen_toString_'.type)(s:zen_settings, current, type, inline, filters, itemno, indent)
|
||||||
elseif s:zen_isExtends(type, "css")
|
elseif s:zen_isExtends(type, "css")
|
||||||
let inner = s:zen_toString_css(s:zen_settings, current, type, inline, filters, itemno, indent)
|
let inner = zencoding#css#toString(s:zen_settings, current, type, inline, filters, itemno, indent)
|
||||||
elseif s:zen_useFilter(filters, 'haml')
|
elseif zencoding#useFilter(filters, 'haml')
|
||||||
let inner = s:zen_toString_haml(s:zen_settings, current, type, inline, filters, itemno, indent)
|
let inner = zencoding#haml#toString(s:zen_settings, current, type, inline, filters, itemno, indent)
|
||||||
else
|
else
|
||||||
let inner = s:zen_toString_html(s:zen_settings, current, type, inline, filters, itemno, indent)
|
let inner = zencoding#html#toString(s:zen_settings, current, type, inline, filters, itemno, indent)
|
||||||
endif
|
endif
|
||||||
if current.multiplier > 1
|
if current.multiplier > 1
|
||||||
let inner = substitute(inner, '\$#', '$line'.(itemno+1).'$', 'g')
|
let inner = substitute(inner, '\$#', '$line'.(itemno+1).'$', 'g')
|
||||||
@@ -585,7 +418,7 @@ function! s:zen_toString(...)
|
|||||||
let tmp = substitute(tmp, '|', '${cursor}', 'g')
|
let tmp = substitute(tmp, '|', '${cursor}', 'g')
|
||||||
endif
|
endif
|
||||||
let tmp = substitute(tmp, '\${zenname}', current.name, 'g')
|
let tmp = substitute(tmp, '\${zenname}', current.name, 'g')
|
||||||
if s:zen_isExtends(type, "css") && s:zen_useFilter(filters, 'fc')
|
if s:zen_isExtends(type, "css") && zencoding#useFilter(filters, 'fc')
|
||||||
let tmp = substitute(tmp, '^\([^:]\+\):\([^;]*;\)', '\1: \2', '')
|
let tmp = substitute(tmp, '^\([^:]\+\):\([^;]*;\)', '\1: \2', '')
|
||||||
if current.important
|
if current.important
|
||||||
let tmp = substitute(tmp, ';', ' !important;', '')
|
let tmp = substitute(tmp, ';', ' !important;', '')
|
||||||
@@ -607,7 +440,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, filters)
|
let inner .= zencoding#toString(n, type, inline, filters)
|
||||||
endfor
|
endfor
|
||||||
let inner = substitute(inner, "\n", "\n" . indent, 'g')
|
let inner = substitute(inner, "\n", "\n" . indent, 'g')
|
||||||
endif
|
endif
|
||||||
@@ -615,7 +448,7 @@ function! s:zen_toString(...)
|
|||||||
endif
|
endif
|
||||||
let itemno = itemno + 1
|
let itemno = itemno + 1
|
||||||
endwhile
|
endwhile
|
||||||
if s:zen_useFilter(filters, 'e')
|
if zencoding#useFilter(filters, 'e')
|
||||||
let str = substitute(str, '&', '\&', 'g')
|
let str = substitute(str, '&', '\&', 'g')
|
||||||
let str = substitute(str, '<', '\<', 'g')
|
let str = substitute(str, '<', '\<', 'g')
|
||||||
let str = substitute(str, '>', '\>', 'g')
|
let str = substitute(str, '>', '\>', 'g')
|
||||||
@@ -705,14 +538,14 @@ function! zencoding#expandAbbr(mode) range
|
|||||||
endif
|
endif
|
||||||
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, 0, filters)
|
let expand .= zencoding#toString(item, type, 0, filters)
|
||||||
endfor
|
endfor
|
||||||
let line = getline(a:firstline)
|
let line = getline(a:firstline)
|
||||||
let part = substitute(line, '^\s*', '', '')
|
let part = substitute(line, '^\s*', '', '')
|
||||||
for n in range(a:firstline, a:lastline)
|
for n in range(a:firstline, a:lastline)
|
||||||
let lline = getline(n)
|
let lline = getline(n)
|
||||||
let lpart = substitute(lline, '^\s\+', '', '')
|
let lpart = substitute(lline, '^\s\+', '', '')
|
||||||
if s:zen_useFilter(filters, 't')
|
if zencoding#useFilter(filters, 't')
|
||||||
let lpart = substitute(lpart, '^[0-9.-]\+\s\+', '', '')
|
let lpart = substitute(lpart, '^[0-9.-]\+\s\+', '', '')
|
||||||
let lpart = substitute(lpart, '\s\+$', '', '')
|
let lpart = substitute(lpart, '\s\+$', '', '')
|
||||||
endif
|
endif
|
||||||
@@ -748,7 +581,7 @@ function! zencoding#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, 0, filters)
|
let expand .= zencoding#toString(item, type, 0, filters)
|
||||||
endfor
|
endfor
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
@@ -778,7 +611,7 @@ function! zencoding#expandAbbr(mode) range
|
|||||||
endif
|
endif
|
||||||
let items = s:zen_parseIntoTree(str, type).child
|
let items = s:zen_parseIntoTree(str, type).child
|
||||||
for item in items
|
for item in items
|
||||||
let expand .= s:zen_toString(item, type, 0, filters)
|
let expand .= zencoding#toString(item, type, 0, filters)
|
||||||
endfor
|
endfor
|
||||||
let expand = substitute(expand, '\$line\([0-9]\+\)\$', '\=submatch(1)', 'g')
|
let expand = substitute(expand, '\$line\([0-9]\+\)\$', '\=submatch(1)', 'g')
|
||||||
endif
|
endif
|
||||||
@@ -902,7 +735,7 @@ function! zencoding#imageSize()
|
|||||||
endif
|
endif
|
||||||
let current.attr.width = width
|
let current.attr.width = width
|
||||||
let current.attr.height = height
|
let current.attr.height = height
|
||||||
let html = s:zen_toString(current, 'html', 1)
|
let html = zencoding#toString(current, 'html', 1)
|
||||||
call s:change_content(img_region, html)
|
call s:change_content(img_region, html)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@@ -1171,7 +1004,7 @@ function! zencoding#anchorizeURL(flag)
|
|||||||
let a = s:zen_parseTag('<a>')
|
let a = s:zen_parseTag('<a>')
|
||||||
let a.attr.href = url
|
let a.attr.href = url
|
||||||
let a.value = '{' . title . '}'
|
let a.value = '{' . title . '}'
|
||||||
let expand = s:zen_toString(a, 'html', 0, [])
|
let expand = zencoding#toString(a, 'html', 0, [])
|
||||||
let expand = substitute(expand, '\${cursor}', '', 'g')
|
let expand = substitute(expand, '\${cursor}', '', 'g')
|
||||||
else
|
else
|
||||||
let body = s:get_text_from_html(content)
|
let body = s:get_text_from_html(content)
|
||||||
@@ -1189,7 +1022,7 @@ function! zencoding#anchorizeURL(flag)
|
|||||||
let cite = s:zen_parseTag('<cite>')
|
let cite = s:zen_parseTag('<cite>')
|
||||||
let cite.value = '{' . url . '}'
|
let cite.value = '{' . url . '}'
|
||||||
call add(blockquote.child, cite)
|
call add(blockquote.child, cite)
|
||||||
let expand = s:zen_toString(blockquote, 'html', 0, [])
|
let expand = zencoding#toString(blockquote, 'html', 0, [])
|
||||||
let expand = substitute(expand, '\${cursor}', '', 'g')
|
let expand = substitute(expand, '\${cursor}', '', 'g')
|
||||||
let indent = substitute(getline('.'), '^\(\s*\).*', '\1', '')
|
let indent = substitute(getline('.'), '^\(\s*\).*', '\1', '')
|
||||||
let expand = substitute(expand, "\n", "\n" . indent, 'g')
|
let expand = substitute(expand, "\n", "\n" . indent, 'g')
|
||||||
@@ -1411,7 +1244,7 @@ function! zencoding#ExpandWord(abbr, type, orig)
|
|||||||
let items = s:zen_parseIntoTree(str, a:type).child
|
let items = s:zen_parseIntoTree(str, a:type).child
|
||||||
let expand = ''
|
let expand = ''
|
||||||
for item in items
|
for item in items
|
||||||
let expand .= s:zen_toString(item, a:type, 0, filters)
|
let expand .= zencoding#toString(item, a:type, 0, filters)
|
||||||
endfor
|
endfor
|
||||||
if a:orig == 0
|
if a:orig == 0
|
||||||
let expand = substitute(expand, '\${lang}', s:zen_settings.lang, 'g')
|
let expand = substitute(expand, '\${lang}', s:zen_settings.lang, 'g')
|
||||||
|
|||||||
3
autoload/zencoding/css.vim
Normal file
3
autoload/zencoding/css.vim
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
function! zencoding#css#toString(settings, current, type, inline, filters, itemno, indent)
|
||||||
|
return ''
|
||||||
|
endfunction
|
||||||
65
autoload/zencoding/haml.vim
Normal file
65
autoload/zencoding/haml.vim
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
function! zencoding#haml#toString(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 = ''
|
||||||
|
let current_name = current.name
|
||||||
|
let current_name = substitute(current.name, '\$$', itemno+1, '')
|
||||||
|
if len(current.name) > 0
|
||||||
|
let str .= '%' . current_name
|
||||||
|
let tmp = ''
|
||||||
|
for attr in keys(current.attr)
|
||||||
|
let val = current.attr[attr]
|
||||||
|
while val =~ '\$\([^#{]\|$\)'
|
||||||
|
let val = substitute(val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||||
|
endwhile
|
||||||
|
let attr = substitute(attr, '\$$', itemno+1, '')
|
||||||
|
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 .= "/"
|
||||||
|
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 .= zencoding#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
|
||||||
96
autoload/zencoding/html.vim
Normal file
96
autoload/zencoding/html.vim
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
function! zencoding#html#toString(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 zencoding#useFilter(filters, 'c')
|
||||||
|
let comment_indent = substitute(str, '^.*\(\s*\)$', '\1', '')
|
||||||
|
endif
|
||||||
|
let current_name = current.name
|
||||||
|
let current_name = substitute(current.name, '\$$', itemno+1, '')
|
||||||
|
let tmp = '<' . current_name
|
||||||
|
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]
|
||||||
|
while val =~ '\$\([^#{]\|$\)'
|
||||||
|
let val = substitute(val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||||
|
endwhile
|
||||||
|
let attr = substitute(attr, '\$$', itemno+1, '')
|
||||||
|
let tmp .= ' ' . attr . '="' . val . '"'
|
||||||
|
if zencoding#useFilter(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 = zencoding#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
|
||||||
|
if inner =~ "\n$"
|
||||||
|
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 .= ">\n" . indent . inner . indent . "\n</" . current_name . ">\n"
|
||||||
|
endif
|
||||||
|
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
|
||||||
Reference in New Issue
Block a user