Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could you also support jinja templates? #22

Closed
pgjones opened this issue May 24, 2021 · 6 comments
Closed

Could you also support jinja templates? #22

pgjones opened this issue May 24, 2021 · 6 comments
Labels

Comments

@pgjones
Copy link
Contributor

pgjones commented May 24, 2021

Thanks for building this, its been on my wish list for a while.

I think it wouldn't be too hard to support Jinja2 templates as well (I think the syntax is very similar), would this be something you are willing to do?

@JaapJoris
Copy link
Member

Thank you for the excellent suggestion! I've had a quick browse through https://jinja.palletsprojects.com/templates/ and if I'm not mistaken, DjHTML currently already supports all of the main constructs in Jinja templates. In particular, the doc's opening example is rendered correctly by DjHTML:

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>My Webpage</title>
    </head>
    <body>
        <ul id="navigation">
            {% for item in navigation %}
                <li><a href="{{ item.href }}">{{ item.caption }}</a></li>
            {% endfor %}
        </ul>

        <h1>My Webpage</h1>
        {{ a_variable }}

        {# a comment #}
    </body>
</html>

What Jinja syntax would still need to be implemented in DjHTML for full Jinja2 support?

@JaapJoris JaapJoris added the yes label May 24, 2021
@notpushkin
Copy link

There might be some good examples here? https://github.com/justrhysism/prettier-plugin-nunjucks/tree/master/tests I'm not sure if those would be in scope of this project but still might be worth looking into :-) You can also state the support for Jinja2 (and maybe Twig/Nunjucks?) in README, if you do want to support it.

And of course, thank you so much for this project! This is something long awaited by the Jinja2 user community in particular.

@JaapJoris
Copy link
Member

I have updated the documentation to explicitly announce Jinja2 support!

I will close this issue now, but if you (or any other Jinja user) has any issues regarding the processing of Jinja2 templates, let it be known that you are more than welcome to open new issues! 🤗

JaapJoris added a commit that referenced this issue May 25, 2021
@pgjones
Copy link
Contributor Author

pgjones commented May 25, 2021

This is great, thank you.

@davidism
Copy link

davidism commented May 26, 2021

Really nice to see this, thank you!

Some other things to consider in the future:

  • Jinja has comment syntax, can't remember if Django does.
  • Jinja's delimiters can be customized.
  • Jinja has a "line statement" syntax that can be enabled by specifying delimiters for it.

@notpushkin
Copy link

@davidism It seems that Django has a syntax similar to Jinja's ({# ... #}) that only works as a single line for some reason (they also have {% comment %} block for multiline comments). I'm not sure though if there's any sensible way to support comments except treating them as raw strings?

JaapJoris added a commit that referenced this issue May 30, 2021
Previously, `{# ... #}` comments were only recognized if they were opened
and closed on the same line. This commit allows them to span multiple lines.
As with the other comment tags, anything inside is ignored.

Thanks to @notpushkin for pointing this out!

Ref. #22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants