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

Teach template_parser.py about jinja2 whitespace markers. #11516

Open
rishig opened this issue Feb 10, 2019 · 12 comments
Open

Teach template_parser.py about jinja2 whitespace markers. #11516

rishig opened this issue Feb 10, 2019 · 12 comments

Comments

@rishig
Copy link
Member

rishig commented Feb 10, 2019

Being able to use http://jinja.pocoo.org/docs/2.10/templates/#whitespace-control feature would greatly increase the readibility of our template files. Currently tools/lib/template_parser.py doesn't seem to know about this feature.

To get the error, you can edit a file like templates/zerver/emails/password_reset.source, and replace a {% trans %}, {% endtrans %} pair with {% trans -%}, {%- endtrans %}. Then run tools/lint templates/zerver/emails/password_reset.source.

@zulipbot
Copy link
Member

Hello @zulip/server-tooling members, this issue was labeled with the "area: tooling" label, so you may want to check it out!

@amanpro30
Copy link
Collaborator

@zulipbot claim

@zulipbot
Copy link
Member

Hello @amanpro30, it looks like you've currently claimed 1 issue in this repository. We encourage new contributors to focus their efforts on at most 1 issue at a time, so please complete your work on your other claimed issues before trying to claim this issue again.

We look forward to your valuable contributions!

@timabbott
Copy link
Sponsor Member

@adnrs96 this is probably an issue for you given your background with the template parser.

@kskonanur
Copy link
Collaborator

@zulipbot claim

@zulipbot
Copy link
Member

zulipbot commented Apr 7, 2019

Hello @kskonanur, it looks like we've already sent you a collaboration invite at https://github.com/zulip/zulip/invitations, but you haven't accepted it yet!

Please accept the invite and try to claim this issue again afterwards. We look forward to your contributions!

@ayushah
Copy link
Collaborator

ayushah commented Apr 8, 2019

@zulipbot claim

@zulipbot
Copy link
Member

zulipbot commented Apr 8, 2019

Welcome to Zulip, @ayushah! We just sent you an invite to collaborate on this repository at https://github.com/zulip/zulip/invitations. Please accept this invite in order to claim this issue and begin a fun, rewarding experience contributing to Zulip!

Here's some tips to get you off to a good start:

As you work on this issue, you'll also want to refer to the Zulip code contribution guide, as well as the rest of the developer documentation on that site.

See you on the other side (that is, the pull request side)!

@ayushah
Copy link
Collaborator

ayushah commented Apr 13, 2019

@zulipbot abandon

@refeed
Copy link
Member

refeed commented Apr 14, 2019

@zulipbot claim

@andersk
Copy link
Member

andersk commented Oct 24, 2019

Reopening because this fix was incomplete. Jinja2 allows you to strip independently from either side of a variable, block, or comment.

$ echo '{%- set x = 1 %}' > test.html
$ tools/pretty-print-html test.html
Prettifying: test.html
Traceback (most recent call last):
  File "/srv/zulip/tools/lib/template_parser.py", line 163, in tokenize
    s = get_jinja2_whitespace_stripped_tag(text, state.i)
  File "/srv/zulip/tools/lib/template_parser.py", line 373, in get_jinja2_whitespace_stripped_tag
    raise TokenizationException('Tag missing "-%}"', text[i:end+2])
lib.template_parser.TokenizationException: ('Tag missing "-%}"', '{%- set x = 1 %}')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "tools/pretty-print-html", line 21, in <module>
    clean_html(filenames)
  File "tools/pretty-print-html", line 12, in clean_html
    phtml = pretty_print_html(html)
  File "/srv/zulip/tools/lib/pretty_print.py", line 15, in pretty_print_html
    tokens = tokenize(html)
  File "/srv/zulip/tools/lib/template_parser.py", line 172, in tokenize
    e.line_content))
lib.template_parser.TemplateParserException: Tag missing "-%}" at Line 1 Col 1:"{%- set x = 1 %}"

@andersk andersk reopened this Oct 24, 2019
@timabbott
Copy link
Sponsor Member

@vrongmeal do you want to take the project of fixing the remaining issue here?

@refeed refeed removed their assignment May 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants