简体   繁体   English

格式化HTML代码

[英]Formatting HTML code

aI have a relatively sophisticated model that I need to render in HTML. 我有一个相对复杂的模型,需要用HTML呈现。

The problem I have is that a single line from the model could be significantly long and this will make the HTML code hard to read. 我的问题是模型中的一行可能会很长,这将使HTML代码难以阅读。 Indenting separate tags does not work because it will create undesired spaces in the middle of the data. 缩进单独的标签不起作用,因为它会在数据中间创建不希望有的空格。

For example if I have data that renders like: 例如,如果我有呈现如下的数据:

<p style="..."><span style="...">...</span><span style="...">...</span><span style="...">...</span><span style="...">...</span></p>

something like 就像是

<p
    style="..."><span 
        style="...">...</span><span 
        style="...">...</span><span 
        style="...">...</span><span 
        style="...">...</span>
</p>

The problem with this is obvious, the opening tag is at the end of the previous line. 这个问题很明显,开始标签在前一行的末尾。

Is there a better option to achieve this? 有没有更好的选择来实现这一目标?

It looks like your trying to avoid the space caused by the line breaks between span elements. 您似乎在尝试避免由span元素之间的换行引起的空间。 If so you could try this trick. 如果是这样,您可以尝试此技巧。 Still ugly but better than a single line. 仍然难看,但比单行更好。

   <span>a</span><!--
--><span>b</span><!--
--><span>c</span>

Maybe take a look at this Remove whitespace and line breaks between HTML elements using jQuery 也许看看这个使用jQuery删除HTML元素之间的空格和换行符

and see if having a little jquery clean up the line breaks for you will help 看看是否有一点jquery为您清理换行符会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM