mirror of
https://github.com/mattn/emmet-vim.git
synced 2025-12-07 03:04:27 +08:00
inline elements
This commit is contained in:
14
unittest.vim
14
unittest.vim
@@ -100,13 +100,19 @@ finish
|
|||||||
'name': "a>b>c<d",
|
'name': "a>b>c<d",
|
||||||
'query': "a>b>c<d",
|
'query': "a>b>c<d",
|
||||||
'type': "html",
|
'type': "html",
|
||||||
'result': "<a href=\"\">\n\t<b>\n\t\t<c></c>\n\t</b>\n\t<d></d>\n</a>\n",
|
'result': "<a href=\"\"><b><c></c></b><d></d></a>\n",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'name': "a>b>c<<d",
|
'name': "a>b>c<<d",
|
||||||
'query': "a>b>c<<d",
|
'query': "a>b>c<<d",
|
||||||
'type': "html",
|
'type': "html",
|
||||||
'result': "<a href=\"\">\n\t<b>\n\t\t<c></c>\n\t</b>\n</a>\n<d></d>\n",
|
'result': "<a href=\"\"><b><c></c></b></a>\n<d></d>\n",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'name': "blockquote>b>c<<d",
|
||||||
|
'query': "blockquote>b>c<<d",
|
||||||
|
'type': "html",
|
||||||
|
'result': "<blockquote>\n\t<b><c></c></b>\n</blockquote>\n<d></d>\n",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'name': "a[href=foo][class=bar]",
|
'name': "a[href=foo][class=bar]",
|
||||||
@@ -136,7 +142,7 @@ finish
|
|||||||
'name': "a{foo}*2>b",
|
'name': "a{foo}*2>b",
|
||||||
'query': "a{foo}*2>b",
|
'query': "a{foo}*2>b",
|
||||||
'type': "html",
|
'type': "html",
|
||||||
'result': "<a href=\"\">\n\tfoo<b></b>\n</a>\n<a href=\"\">\n\tfoo<b></b>\n</a>\n",
|
'result': "<a href=\"\">foo<b></b></a>\n<a href=\"\">foo<b></b></a>\n",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'name': "a*2{foo}>b",
|
'name': "a*2{foo}>b",
|
||||||
@@ -196,7 +202,7 @@ finish
|
|||||||
'name': "a>b>c<<div",
|
'name': "a>b>c<<div",
|
||||||
'query': "a>b>c<<div",
|
'query': "a>b>c<<div",
|
||||||
'type': "html",
|
'type': "html",
|
||||||
'result': "<a href=\"\">\n\t<b>\n\t\t<c></c>\n\t</b>\n</a>\n<div></div>\n",
|
'result': "<a href=\"\"><b><c></c></b></a>\n<div></div>\n",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'name': "(#header>h1)+#content+#footer",
|
'name': "(#header>h1)+#content+#footer",
|
||||||
|
|||||||
@@ -1001,6 +1001,11 @@ function! s:zen_toString(...)
|
|||||||
let type = ''
|
let type = ''
|
||||||
endif
|
endif
|
||||||
if len(type) == 0 | 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 has_key(s:zen_settings[type], 'indentation')
|
if has_key(s:zen_settings[type], 'indentation')
|
||||||
let indent = s:zen_settings[type].indentation
|
let indent = s:zen_settings[type].indentation
|
||||||
@@ -1011,6 +1016,11 @@ function! s:zen_toString(...)
|
|||||||
let str = ''
|
let str = ''
|
||||||
while m < current.multiplier
|
while m < current.multiplier
|
||||||
if len(current.name) && type == 'html'
|
if len(current.name) && type == 'html'
|
||||||
|
if stridx(','.s:zen_settings[type].inline_elements.',', ','.current.name.',') != -1
|
||||||
|
let child_inline = 1
|
||||||
|
else
|
||||||
|
let child_inline = 0
|
||||||
|
endif
|
||||||
let str .= '<' . current.name
|
let str .= '<' . current.name
|
||||||
for attr in keys(current.attr)
|
for attr in keys(current.attr)
|
||||||
if current.multiplier > 1 && current.attr[attr] =~ '\$'
|
if current.multiplier > 1 && current.attr[attr] =~ '\$'
|
||||||
@@ -1020,22 +1030,39 @@ function! s:zen_toString(...)
|
|||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
let inner = current.value[1:-2]
|
let inner = current.value[1:-2]
|
||||||
|
if stridx(','.s:zen_settings[type].inline_elements.',', ','.current.name.',') != -1
|
||||||
|
let child_inline = 1
|
||||||
|
else
|
||||||
|
let child_inline = 0
|
||||||
|
endif
|
||||||
for child in current.child
|
for child in current.child
|
||||||
let inner .= s:zen_toString(child, type)
|
let inner .= s:zen_toString(child, type, child_inline)
|
||||||
endfor
|
endfor
|
||||||
if len(current.child)
|
if len(current.child)
|
||||||
let inner = substitute(inner, "\n", "\n" . indent, 'g')
|
if inline == 0
|
||||||
let inner = substitute(inner, indent . "$", "", 'g')
|
if stridx(','.s:zen_settings[type].inline_elements.',', ','.current.name.',') == -1
|
||||||
let str .= ">\n" . indent . inner . "</" . current.name . ">\n"
|
let inner = substitute(inner, "\n", "\n" . indent, 'g')
|
||||||
else
|
let inner = substitute(inner, indent . "$", "", 'g')
|
||||||
if stridx(','.s:zen_settings[type].empty_elements.',', ','.current.name.',') != -1
|
let str .= ">\n" . indent . inner . "</" . current.name . ">\n"
|
||||||
let str .= " />\n"
|
|
||||||
else
|
|
||||||
if stridx(','.s:zen_settings[type].block_elements.',', ','.current.name.',') != -1 && len(current.child)
|
|
||||||
let str .= ">\n" . inner . "|</" . current.name . ">\n"
|
|
||||||
else
|
else
|
||||||
let str .= ">" . inner . "|</" . current.name . ">\n"
|
let str .= ">" . inner . "</" . current.name . ">\n"
|
||||||
endif
|
endif
|
||||||
|
else
|
||||||
|
let str .= ">" . inner . "</" . current.name . ">"
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
if inline == 0
|
||||||
|
if stridx(','.s:zen_settings[type].empty_elements.',', ','.current.name.',') != -1
|
||||||
|
let str .= " />\n"
|
||||||
|
else
|
||||||
|
if stridx(','.s:zen_settings[type].inline_elements.',', ','.current.name.',') == -1 && len(current.child)
|
||||||
|
let str .= ">\n" . inner . "|</" . current.name . ">\n"
|
||||||
|
else
|
||||||
|
let str .= ">" . inner . "|</" . current.name . ">\n"
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
let str .= ">" . inner . "|</" . current.name . ">"
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
@@ -1049,7 +1076,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)
|
let inner .= s:zen_toString(n, type, inline)
|
||||||
endfor
|
endfor
|
||||||
let inner = substitute(inner, "\n", "\n" . indent, 'g')
|
let inner = substitute(inner, "\n", "\n" . indent, 'g')
|
||||||
endif
|
endif
|
||||||
|
|||||||
Reference in New Issue
Block a user