Skip to content

Conversation

@dannycolin
Copy link

Add a prettier parser for Pontoon jinja templates.

Signed-off-by: Danny Colin <contact@dannycolin.com>
Signed-off-by: Danny Colin <contact@dannycolin.com>
@mathjazz
Copy link
Collaborator

Nice work, Danny!

Please check the failing workflow.

@flodolo
Copy link
Collaborator

flodolo commented Feb 10, 2026

Worth noting that I see additional diff if I run make format locally with this PR.

Some of these errors (already closed html or tbody) feel off 🤔
For example, I can't spot a second </tbody> in team list.

@flodolo
Copy link
Collaborator

flodolo commented Feb 10, 2026

I checked again pontoon/teams/templates/teams/widgets/team_list.html, and I realized I have misread the error.

SyntaxError: Unexpected closing tag "tbody". It may happen when the tag has already been closed by another tag.

As @mathjazz pointed out while were discussing this, I think the problem is that there's a macro opening the <tbody> tag, then there's a second macro closing it, but the parser only knows about one macro at a time. So, either ignore the error or rewrite the template to have the full table markup within a macro.

@dannycolin
Copy link
Author

@flodolo You're right. The parser works by:

  1. temporarily replace jinja with placeholders
  2. pipe the output to the html parser
  3. readd the jinja code

This means it's impossible to have separated opening/closing tags wrapped in a conditional (or macro) statement. It's also impossible to have tags partially generated by jinja (e.g. <h{{ level }}). Before I start fixing the linting errors, @mathjazz do you think it's still worth implementing knowing the parser limitations?

References:

@mathjazz mathjazz linked an issue Feb 11, 2026 that may be closed by this pull request
@mathjazz
Copy link
Collaborator

Before I start fixing the linting errors, @mathjazz do you think it's still worth implementing knowing the parser limitations?

It seems like there's just 9 files with errors in total? Some of the errors seem legit, others I'd fix by changing the structure or excluding the lines from formatting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Introduce formatter for Jinja2 templates

3 participants