如何防止由于 HTML 代码中的换行符而导致输出中出现空格?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16403330/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to prevent space in output due to line break in the HTML code?
提问by Barney
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 jinja2python template engine. Does it have some space-preventing trick?
我现在正在使用jinja2python 模板引擎。它有什么防止空间的技巧吗?
UPDATE:
更新:
With jinja2, thanks to dav1d, the shortest way I could come up with is:
使用 jinja2,感谢 dav1d,我能想到的最短方法是:
<a>{% if true -%}
No space in the output before this text.
</a>{% endif -%}
Nor after.
Is there any shorter way of doing this?
有没有更短的方法来做到这一点?
回答by dav1d
Jinja2 WhiteSpace Control is what you need (according to your reponse to my comment): http://jinja.pocoo.org/docs/templates/#whitespace-control
Jinja2 WhiteSpace Control 是您所需要的(根据您对我的评论的回应):http: //jinja.pocoo.org/docs/templates/#whitespace-control
回答by maedox
This should do what you want:
这应该做你想做的:
{# -#}
回答by Soumya Mukhija
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>