rtts / djhtml

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

CSS Indentation inside Block used for css extension #110

Closed BonaFideIT0 closed 4 months ago

BonaFideIT0 commented 7 months ago

A pretty common usecase is to have a base template that looks something like that:

<style>
    {% block style %}
        .somecss {
            someproperty: somevalue;
        }
    {% endblock %}
</style>

Next we have a template extending this template like so:

{% block style %}
    {{ block.super }}
    .somemorecss {
        somemoreproperty: somemorevalue;
    }
{% endblock %}

After running the hook we get something that looks like this in the extended template:

{% block style %}
    {{ block.super }}
    .somemorecss {
    somemoreproperty: somemorevalue;
    }
{% endblock %}

I guess thats due to the fact that the parser does not encounter a style tag beforehand?

Is there something you can do about that?

Sincere thanks for your work so far. :)

JaapJoris commented 4 months ago

I guess thats due to the fact that the parser does not encounter a style tag beforehand?

That is correct. DjHTML "thinks" it's still in HTML mode, because it hasn't encountered any indication that it isn't. A possible solution would be to introduce something like a {# fmt:css #} tag to force evaluation in CSS mode. I'll see what I can do!

BonaFideIT0 commented 4 months ago

Much appreciated, thanks. :)

JaapJoris commented 4 months ago

Unfortunately, I have to conclude (again) that supporting a {# fmt:<mode> #} tag is hard without running into inconsistencies in the InsideHTMLTag mode. It's the most complicated (read "hacky") mode in DjHTML, but I like the way it currently performs and I don't want to change it.

It is feasible to implement {# fmt:mode #} inside all modes except that one, though. However, it would not be consistent (read "fair") to support {# fmt:mode #} in some places and not in others, so I'd rather not support it at all. After all, there already exists {# fmt:off #} and {# fmt:on #} as an "escape hatch" for all cases that DjHTML doesn't support.

So, I've decided to also close this issue as wontfix. My apologies.

oruehenbeck commented 4 months ago

Hi Joris,

thanks for your consideration. I think our options are

Considering No. 3 is the cleanest one, we will move forward with that.

I consider your tool a handy way to have consistant styling over a big project with multiple colaborating coders which is unfortunately littered with legacy code.

Besides this issue, it works pretty consistently and we will clean the legacy code up with time and resolve the issue this way.

Thanks again for your good work. :)