harttle / liquidjs

A simple, expressive, safe and Shopify compatible template engine in pure JavaScript.
https://liquidjs.com
MIT License
1.5k stars 237 forks source link

Indentation improvement #656

Closed cdtut closed 1 month ago

cdtut commented 9 months ago

To get proper indented output like this:

<div>
    1
    2
    3
</div>

You need to write:

<div>
    1
    {% for xxx %}
    {% if xxx %}
    2
    {% endif %}
    {% endfor %}
    {% if xxx %}
    3
    {% endif %}
</div>

This is better to read and organize:

<div>
    1
    {% for xxx %}
        {% if xxx %}
            2
        {% endif %}
    {% endfor %}
    {% if xxx %}
        3
    {% endif %}
</div>

But output is like this:

<div>
    1
            2
        3
</div>

If a tag is on its own line liquid should detect the starting indent level of the outer tag and put the inner content on same indent level.