Barney Szabolcs
Barney Szabolcs

Reputation: 12534

How to prevent space in output due to line break in the HTML code?

I have seen this question up here and some are solving it by comment tags or breaking tags like this:

 <i><!--
-->t does not work on the first level with tabspace = 2
   beside it looks horrible.  
<a
 >nnoying<
/a> is it not?

I remember as if I have seen some trick like

<a>&dont_put_here_space_please;
  tricky ampersand code.

Is there any such thing?

I am using now jinja2 python template engine. Does it have some space-preventing trick?

UPDATE:

With jinja2, thanks to dav1d, the shortest way I could come up with is:

<a>{% if true -%}
  No space in the output before this text.
</a>{% endif -%}
  Nor after.

Is there any shorter way of doing this?

Upvotes: 19

Views: 33365

Answers (3)

Soumya Mukhija
Soumya Mukhija

Reputation: 29

I know this is an old question but I'd like to share how I got it to work around in my code: Using span.

<span> .../line1... /line2 ... </span>

Upvotes: 0

maedox
maedox

Reputation: 181

This should do what you want:

{# -#}

Upvotes: 9

dav1d
dav1d

Reputation: 6055

Jinja2 WhiteSpace Control is what you need (according to your reponse to my comment): http://jinja.pocoo.org/docs/templates/#whitespace-control

Upvotes: 15

Related Questions