noahmorrison / chevron

A Python implementation of mustache
MIT License
505 stars 55 forks source link

Leading whitespace not preserved when using partials #49

Closed cocoroutine closed 5 years ago

cocoroutine commented 5 years ago

Leading whitespace is not preserved when looping through a list in a partial. It gets weirder when you have nested blocks with tags. Examples below. Tested on 0.13.1

template

<xml>
                <partial>
                {{>partial}}
                </partial>
</xml>

partial

{{#items}}
    {{#numbers}}
    <number>
        {{.}}
    </number>
    {{/numbers}}
{{/items}}

data

data = { 'items': { 'numbers':  [ 'one', 'two' ] } }  

Expected output

<xml>
                <partial>
                    <number>
                        one
                    </number>
                    <number>
                        two
                   </number>
                </partial>
</xml>

Actual output

<xml>
                <partial>
                    <number>
        one
    </number>
    <number>
        two
    </number>
                </partial>
</xml>

Nested blocks, weirder

partial_worse

{{#items}}
<items>
    {{#numbers}}
    <number>
        {{.}}
    </number>
    {{/numbers}}
</items>
{{/items}}

Actual output

<xml>
                <partial>
                <items>
                    <number>
        one
    </number>
    <number>
        two
    </number>
</items>
                </partial>
</xml>
dmorrison42 commented 5 years ago

Could not reproduce strictly as written.

Additionally Standalone Indentation passes.

It is possible that this has something to do with using tabs for indentation, as it looks like padding state is an integer instead of a string, but it's hard to be sure.