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

Ignore whitespace around templatel tags #13

Open
markokocic opened this issue Mar 18, 2021 · 2 comments
Open

Ignore whitespace around templatel tags #13

markokocic opened this issue Mar 18, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@markokocic
Copy link
Collaborator

If a line inside a template contains only templatel directives and whitespace, the complete line should be removed from the output when rendered.

Use case 1:

template for RSS xml feed:

{# feed.xml; -*- Mode: jinja2; -*- #}
<?xml version="1.0" encoding="UTF-8" ?>

is rendered like

<?xml version="1.0" encoding="UTF-8" ?>

Note the empty line at the begining is making this file invalid xml file.

Use case 2:

      <ul>
        {% for post in posts %}
          <li>
            <section>
                <h3>{{ post.date|strftime(date_format) }} - <a href="{{ post.url }}">{{ post.title }}</a></h3>
                {% if post.description %}<p>{{ post.description }}</p>{% endif %}
            </section>
          </li>
        {% endfor %}
      </ul>

this renders the html output like this:

        
          <li>
            <section>
                <h3>2019-02-22 - <a href="">title 1</a></h3>
                <p>description</p>
            </section>
          </li>
        
          <li>
            <section>
                <h3>2016-11-22 - <a href="">title 2</a></h3>
                
            </section>
          </li>
        
          <li>
            <section>
                <h3>2016-01-04 - <a href="">title 3</a></h3>
                
            </section>
          </li>
        

While the html is valid, it looks ugly with all those empty lines.

As an (aesthetical) enhancement it would be good if templatel would not render at all line that contains only templatel tags and whitespace.

@clarete
Copy link
Collaborator

clarete commented Apr 10, 2021

yeah, it'd be great to support what jinja calls whitespace-control!

@clarete clarete added the enhancement New feature or request label Apr 10, 2021
@emacsbliss
Copy link

emacsbliss commented Jan 29, 2024

I also bump into this issue, would be great to have this support.

I also tried something like {% if abc -%} but it says invalid syntax..

bump the request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants