fix indent. close #27

This commit is contained in:
mattn
2012-06-11 10:05:41 +09:00
parent 4c56e1146e
commit 8551b28a74
2 changed files with 20 additions and 17 deletions

View File

@@ -318,12 +318,17 @@ function! zencoding#lang#html#toString(settings, current, type, inline, filters,
let str .= ">" let str .= ">"
let str .= current.value[1:-2] let str .= current.value[1:-2]
let nc = len(current.child) let nc = len(current.child)
let dr = 0
if nc > 0 if nc > 0
for n in range(nc) for n in range(nc)
let child = current.child[n] let child = current.child[n]
if len(current_name) > 0 && stridx(','.settings.html.inline_elements.',', ','.current_name.',') == -1 if child.multiplier > 1
let str .= "\n" . indent
let dr = 1
elseif len(current_name) > 0 && stridx(','.settings.html.inline_elements.',', ','.current_name.',') == -1
if nc > 1 || (len(child.name) > 0 && stridx(','.settings.html.inline_elements.',', ','.child.name.',') == -1) if nc > 1 || (len(child.name) > 0 && stridx(','.settings.html.inline_elements.',', ','.child.name.',') == -1)
let str .= "\n" . indent let str .= "\n" . indent
let dr = 1
endif endif
endif endif
let inner = zencoding#toString(child, type, 0, filters) let inner = zencoding#toString(child, type, 0, filters)
@@ -334,17 +339,15 @@ function! zencoding#lang#html#toString(settings, current, type, inline, filters,
else else
let str .= '${cursor}' let str .= '${cursor}'
endif endif
if nc > 0 && stridx(','.settings.html.inline_elements.',', ','.current_name.',') == -1 if dr
if nc > 1 || (nc == 1 && len(current.child[0].name) > 0 && stridx(','.settings.html.inline_elements.',', ','.current.child[0].name.',') == -1) let str .= "\n"
let str .= "\n"
endif
endif endif
let str .= "</" . current_name . ">" let str .= "</" . current_name . ">"
endif endif
if len(comment) > 0 if len(comment) > 0
let str .= "\n<!-- /" . comment . " -->" let str .= "\n<!-- /" . comment . " -->"
endif endif
if len(current_name) > 0 && (current.multiplier > 0 && !empty(current.parent) && len(current.parent.child) > 1)|| stridx(','.settings.html.block_elements.',', ','.current_name.',') != -1 if len(current_name) > 0 && current.multiplier > 0 || stridx(','.settings.html.block_elements.',', ','.current_name.',') != -1
let str .= "\n" let str .= "\n"
endif endif
return str return str

View File

@@ -201,7 +201,7 @@ finish
}, },
{ {
'query': "a[title=TITLE]", 'query': "a[title=TITLE]",
'result': "<a href=\"\" title=\"TITLE\"></a>", 'result': "<a href=\"\" title=\"TITLE\"></a>\n",
}, },
{ {
'query': "div#wrapper.box", 'query': "div#wrapper.box",
@@ -233,7 +233,7 @@ finish
}, },
{ {
'query': "a", 'query': "a",
'result': "<a href=\"\"></a>", 'result': "<a href=\"\"></a>\n",
}, },
{ {
'query': "obj", 'query': "obj",
@@ -249,11 +249,11 @@ finish
}, },
{ {
'query': "a[href=http://www.google.com/].foo#hoge", 'query': "a[href=http://www.google.com/].foo#hoge",
'result': "<a id=\"hoge\" href=\"http://www.google.com/\" class=\"foo\"></a>", 'result': "<a id=\"hoge\" href=\"http://www.google.com/\" class=\"foo\"></a>\n",
}, },
{ {
'query': "a[href=http://www.google.com/]{Google}", 'query': "a[href=http://www.google.com/]{Google}",
'result': "<a href=\"http://www.google.com/\">Google</a>", 'result': "<a href=\"http://www.google.com/\">Google</a>\n",
}, },
{ {
'query': "{ZenCoding}", 'query': "{ZenCoding}",
@@ -265,7 +265,7 @@ finish
}, },
{ {
'query': "a>b>i<b", 'query': "a>b>i<b",
'result': "<a href=\"\"><b><i></i></b><b></b></a>", 'result': "<a href=\"\"><b><i></i></b><b></b></a>\n",
}, },
{ {
'query': "a>b>i<<b", 'query': "a>b>i<<b",
@@ -277,11 +277,11 @@ finish
}, },
{ {
'query': "a[href=foo][class=bar]", 'query': "a[href=foo][class=bar]",
'result': "<a href=\"foo\" class=\"bar\"></a>", 'result': "<a href=\"foo\" class=\"bar\"></a>\n",
}, },
{ {
'query': "a[a=b][b=c=d][e]{foo}*2", 'query': "a[a=b][b=c=d][e]{foo}*2",
'result': "<a a=\"b\" b=\"c=d\" e=\"\" href=\"\">foo</a><a a=\"b\" b=\"c=d\" e=\"\" href=\"\">foo</a>", 'result': "<a a=\"b\" b=\"c=d\" e=\"\" href=\"\">foo</a>\n<a a=\"b\" b=\"c=d\" e=\"\" href=\"\">foo</a>\n",
}, },
{ {
'query': "a[a=b][b=c=d][e]*2{foo}", 'query': "a[a=b][b=c=d][e]*2{foo}",
@@ -293,7 +293,7 @@ finish
}, },
{ {
'query': "a{foo}*2>b", 'query': "a{foo}*2>b",
'result': "<a href=\"\">foo<b></b></a><a href=\"\">foo<b></b></a>", 'result': "<a href=\"\">foo<b></b></a>\n<a href=\"\">foo<b></b></a>\n",
}, },
{ {
'query': "a*2{foo}>b", 'query': "a*2{foo}>b",
@@ -317,7 +317,7 @@ finish
}, },
{ {
'query': "a#foo$$$*3", 'query': "a#foo$$$*3",
'result': "<a id=\"foo001\" href=\"\"></a><a id=\"foo002\" href=\"\"></a><a id=\"foo003\" href=\"\"></a>", 'result': "<a id=\"foo001\" href=\"\"></a>\n<a id=\"foo002\" href=\"\"></a>\n<a id=\"foo003\" href=\"\"></a>\n",
}, },
{ {
'query': "ul+", 'query': "ul+",
@@ -381,7 +381,7 @@ finish
}, },
{ {
'query': "a[title=\"Hello', world\" rel]", 'query': "a[title=\"Hello', world\" rel]",
'result': "<a rel=\"\" href=\"\" title=\"Hello', world\"></a>", 'result': "<a rel=\"\" href=\"\" title=\"Hello', world\"></a>\n",
}, },
{ {
'query': "div>a#foo{bar}", 'query': "div>a#foo{bar}",
@@ -464,7 +464,7 @@ finish
'tests': [ 'tests': [
{ {
'query': "img[src=http://mattn.kaoriya.net/images/logo.png]$$$$\\<c-y>,\\<c-y>i$$$$", 'query': "img[src=http://mattn.kaoriya.net/images/logo.png]$$$$\\<c-y>,\\<c-y>i$$$$",
'result': "<img src=\"http://mattn.kaoriya.net/images/logo.png\" alt=\"\" width=\"96\" height=\"96\" />", 'result': "<img src=\"http://mattn.kaoriya.net/images/logo.png\" alt=\"\" width=\"96\" height=\"96\" />\n",
}, },
{ {
'query': "img[src=/logo.png]$$$$\\<c-y>,\\<c-y>i$$$$", 'query': "img[src=/logo.png]$$$$\\<c-y>,\\<c-y>i$$$$",