如何防止HTML代码中的换行导致输出空间?

X''*_*X'' 19 html jinja2

我在这里看到了这个问题,有些是通过评论标签解决它或打破这样的标签:

 <i><!--
-->t does not work on the first level with tabspace = 2
   beside it looks horrible.  
<a
 >nnoying<
/a> is it not?
Run Code Online (Sandbox Code Playgroud)

我记得好像我曾经看到过一些诡计

<a>&dont_put_here_space_please;
  tricky ampersand code.
Run Code Online (Sandbox Code Playgroud)

有这样的事吗?

我正在使用jinja2 python模板引擎.它有一些防空间技巧吗?

更新:

有了jinja2,感谢dav1d,我能想出的最短路径是:

<a>{% if true -%}
  No space in the output before this text.
</a>{% endif -%}
  Nor after.
Run Code Online (Sandbox Code Playgroud)

这样做有什么简短的方法吗?

dav*_*v1d 14

Jinja2 WhiteSpace Control是你需要的(根据你对我的评论的反应):http://jinja.pocoo.org/docs/templates/#whitespace-control


小智 8

这应该做你想要的:

{# -#}
Run Code Online (Sandbox Code Playgroud)