emacs-love / templatel

Jinja inspired template language for Emacs Lisp
https://emacs.love/templatel
GNU General Public License v3.0
54 stars 6 forks source link

Ignore whitespace around templatel tags #13

Open markokocic opened 3 years ago

markokocic commented 3 years ago

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 commented 3 years ago

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

emacsbliss commented 9 months ago

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