From 01b6732fd64b446e267781a6069076ab7f5215ec Mon Sep 17 00:00:00 2001 From: mattn Date: Sun, 10 Jun 2012 02:02:56 +0900 Subject: [PATCH] no need to add cursor when has children. --- autoload/zencoding/lang/html.vim | 32 ++++++++++++++++++-------------- unittest.vim | 2 +- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/autoload/zencoding/lang/html.vim b/autoload/zencoding/lang/html.vim index c16b004..3291546 100644 --- a/autoload/zencoding/lang/html.vim +++ b/autoload/zencoding/lang/html.vim @@ -317,21 +317,25 @@ function! zencoding#lang#html#toString(settings, current, type, inline, filters, else let str .= ">" let str .= current.value[1:-2] - let str .= '${cursor}' - for n in range(len(current.child)) - let child = current.child[n] - if len(current.child) > 0 && stridx(','.settings.html.inline_elements.',', ','.current_name.',') == -1 - if len(current.child) > 1 || stridx(','.settings.html.inline_elements.',', ','.child.name.',') == -1 - let str .= "\n" . indent + let nc = len(current.child) + if nc > 0 + for n in range(nc) + let child = current.child[n] + if stridx(','.settings.html.inline_elements.',', ','.current_name.',') == -1 + if nc > 1 || stridx(','.settings.html.inline_elements.',', ','.child.name.',') == -1 + let str .= "\n" . indent + endif endif - endif - let inner = zencoding#toString(child, type, 0, filters) - let inner = substitute(inner, "\n", "\n" . indent, 'g') - let inner = substitute(inner, "\n" . indent . '$', '', 'g') - let str .= inner - endfor - if len(current.child) > 0 && stridx(','.settings.html.inline_elements.',', ','.current_name.',') == -1 - if len(current.child) > 1 || (len(current.child) == 1 && stridx(','.settings.html.inline_elements.',', ','.current.child[0].name.',') == -1) + let inner = zencoding#toString(child, type, 0, filters) + let inner = substitute(inner, "\n", "\n" . indent, 'g') + let inner = substitute(inner, "\n" . indent . '$', '', 'g') + let str .= inner + endfor + else + let str .= '${cursor}' + endif + if nc > 0 && stridx(','.settings.html.inline_elements.',', ','.current_name.',') == -1 + if nc > 1 || (nc == 1 && stridx(','.settings.html.inline_elements.',', ','.current.child[0].name.',') == -1) let str .= "\n" endif endif diff --git a/unittest.vim b/unittest.vim index 931c7dd..d0e38a2 100644 --- a/unittest.vim +++ b/unittest.vim @@ -425,7 +425,7 @@ finish }, { 'query': "f div.boxes>article.box2>header>(hgroup>h2{aaa}+h3{bbb})+p{ccc}$$$$", - 'result': "f
\n\t
\n\t\t
\n\t\t\t
\n\t\t\t\t

aaa

\n\t\t\t\t

bbb

\n\t\t\t
\n\t\t\t

ccc

\n\t\t
\n\t
\n
\n", + 'result': "f
\n\t
\n\t\t
\n\t\t\t
\n\t\t\t\t

aaa

\n\t\t\t\t

bbb

\n\t\t\t
\n\t\t\t

ccc

\n\t\t
\n\t
\n
", }, { 'query': "div.boxes>(div.box2>section>h2{a}+p{b})+(div.box1>section>h2{c}+p{d}+p{e}+(bq>h2{f}+h3{g})+p{h})",