rtts / djhtml

Django/Jinja template indenter
GNU General Public License v3.0
582 stars 32 forks source link

Jinja's `{% raw %}` and Django's `{% verbatim %}` blocks #39

Closed JaapJoris closed 3 years ago

JaapJoris commented 3 years ago

Jinja's {% raw %} tag disables parsing the containing block for template tags, as in the following example (taken from the documentation):

{% raw %}
    <ul>
    {% for item in seq %}
        <li>{{ item }}</li>
    {% endfor %}
    </ul>
{% endraw %}

DjHTML could support this by also disabling parsing the block for template tags. The result would then look like this:

{% raw %}
    <ul>
        {% for item in seq %}
        <li>{{ item }}</li>
        {% endfor %}
    </ul>
{% endraw %}

However, the main use case of the {% raw %} tag is to present Jinja template tags themselves (in code blocks), and you could argue that:

  1. Code inside code blocks should be properly indented (so DjHTML should not interpret the {% raw %} tag at all)
  2. Code inside code blocks should be left untouched (so DjHTML should interpret the {% raw %} tag the same as a <pre> tag.

Since I'm at a loss here, I'm asking the Jinja community for help: How should the contents of a {% raw %} block be indented?

sjoerdjob commented 3 years ago

Whatever decision is made, I think the same should be made for Django's verbatim.

JaapJoris commented 3 years ago

I have decided to go for the second option. Contents in {% raw %} and {% verbatim %} will now be left untouched by DjHTML.