整理修剪空标签 [英] Tidy trimming empty tags

查看:48
本文介绍了整理修剪空标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨。


(这有点类似于昨天关于空链接的帖子)


我注意到Tidy [0每当遇到空的

标签时发出警告,并在请求清理时剥离这些标签。在某些情况下(例如< tbody>)这是可以的,但对其他标签有问题(例如

< option>)。某些标签(td,th,...)在空的时候不会产生警告

为空。


对于考虑的文件也会发出警告有效

" XHTML 1.0 Strict"由W3C验证器。如果发出任何这些空标签

警告,Tidy建议使用XMTML 1.0 Transitional。相反。

几个例子:

1)空< select>选项

----------------------------------------- ------------------------

< select name =" x">

< option value ="">< / option>

< option value =" foo"> a foo< / option>

< option value =" bar"> a bar< / option>

< / select>


[tidy]警告:修剪空<选项>"

我不知道怎么能避免这个警告。我不想在第一个选项中显示任何

文本,并且像
可以接受。

2)空p,div,span,h1,[href],...标签

- -------------------------------------------------- -------------

< td class =" c1">< span class =" c2">< / span>一些文字< / td>

这样的构造有时被我们的webdesigner用于与CSS结合的
。 span标记在技术上是空的,但是

样式表将导致显示图像。


< div id =" ibox">< ; / div>

这可能发生在例如ibox的情况下。是一个包含主要内容的附加

信息的框,但是没有额外的信息

当前页面。盒子本身仍然应该显示,所以标签是空的。


< p class =" notes"><?= $ notes?>< / p>

空标记也可以作为服务器端脚本的工件出现;如果

$ notes是空的,那么< p>标签(这种情况可以避免,我知道)。

3)空td,th标签;脚本标签

---------------------------------------- -------------------------

< tr>< th>< / th>< / tr> ;

< tr>< td>< / td>< / tr>


Tidy忽略空表格单元格并且不会尝试剥离他们。

< script type =" text / javascript" src =" xxx.js">< / script>

具有src属性的空脚本标签也是如此。

4)清空thead,tfoot标签

-------------------------------------------- ---------------------

< table>

< thead>< tr>< ; td> head< / td>< / tr>< / thead>

< tfoot>< / tfoot>

< tbody>< tr> ;< td> body< / td>< / tr>< / tbody>

< / table>


Tidy发出警告空的tfoot元素,预计

因为< tfoot>绝不能空着。在这种情况下,我实际上会给b $ b而不是警告,因为该文件不再符合
的资格作为有效的XHTML。

我想摆脱1)+ 2)中的警告,简化

自动验证并让我放松心情。在发布

警告和剥离标签时,Tidy是否正确?我应该总是尽量避免空的

标签吗?怎么样,怎么样?

提前谢谢,

Stefan

[0] http://tidy.sourceforge.net/

推荐答案

notes ?>< / p>

空标记也可以作为服务器端脚本的工件出现;如果
notes ?></p>
Empty tags can also occur as an artifact of server-side scripting; if


注释为空,那么< p>标签(这种情况可以避免,我知道)。

3)空td,th标签;脚本标签

---------------------------------------- -------------------------

< tr>< th>< / th>< / tr> ;

< tr>< td>< / td>< / tr>


Tidy忽略空表格单元格并且不会尝试剥离他们。

< script type =" text / javascript" src =" xxx.js">< / script>

具有src属性的空脚本标签也是如此。

4)清空thead,tfoot标签

-------------------------------------------- ---------------------

< table>

< thead>< tr>< ; td> head< / td>< / tr>< / thead>

< tfoot>< / tfoot>

< tbody>< tr> ;< td> body< / td>< / tr>< / tbody>

< / table>


Tidy发出警告空的tfoot元素,预计

因为< tfoot>绝不能空着。在这种情况下,我实际上会给b $ b而不是警告,因为该文件不再符合
的资格作为有效的XHTML。

我想摆脱1)+ 2)中的警告,简化

自动验证并让我放松心情。在发布

警告和剥离标签时,Tidy是否正确?我应该总是尽量避免空的

标签吗?怎么样,怎么样?

提前谢谢,

Stefan

[0] http://tidy.sourceforge.net/
notes is empty, so is the <p> tag (this case can be avoided, I know).
3) Empty td, th tags; script tags
-----------------------------------------------------------------
<tr><th></th></tr>
<tr><td></td></tr>

Tidy ignores empty table cells and does not try to strip them.
<script type="text/javascript" src="xxx.js"></script>
Same goes for empty script tags with src attributes.
4) Empty thead, tfoot tags
-----------------------------------------------------------------
<table>
<thead><tr><td>head</td></tr></thead>
<tfoot></tfoot>
<tbody><tr><td>body</td></tr></tbody>
</table>

Tidy issues a warning for the empty tfoot element, which is expected
because <tfoot> must never be empty. In this case I would actually
rather get an error instead of a warning, because the document does not
qualify as valid XHTML anymore.
I would like to get rid of the warnings in 1) + 2), to simplify
automated validation and to ease my mind. Is Tidy correct in issuing
warnings and stripping the tags? Should I always try to avoid empty
tags? If so, how?
Thanks in advance,
Stefan
[0] http://tidy.sourceforge.net/


Stefan Weiss< sp ** ****@foo.at>写道:
Stefan Weiss <sp******@foo.at> wrote:
警告也针对被认为有效的文件发出
XHTML 1.0 Strict由W3C验证器。


Tidy是一个linter,它有自己关于标记应该如何的规则,没有

与检查DTD的验证器有关。 br />
几个例子:

1)空< select>选项
--------------------------------------------- --------------------
< select name =" x">
< option value =""> < / option>
< option value =" foo"> a foo< / option>
< option value =" bar"> a bar< / option>
< / select>

[tidy]警告:修剪空<选项>


这似乎是合理的,应该删除空选项。

我不知道如何避免这个警告。我不想在第一个选项中显示任何
文字


停止想要那个。

,以及类似< option>的黑客攻击&安培; NBSP;< /选项>是不可接受的。


好​​。

< td class =" c1">< span class =" c2">< / span>一些文字< / td>
这样的构造有时被我们的webdesigner用于与CSS结合。 span标记在技术上是空的,但
样式表将导致显示图像。


没有办法阻止Tidy修剪这些空元素。


理想情况下,Tidy条带的空元素不应该在标记中,

但是在现实世界中没有任何论据可以解释为什么如果熟练的编码人员使用上述类型的代码

不应该使用。


因此,Tidy过度热衷于删除它们,解决方案是对Tidy做什么来清空空间,摆脱它。

Tidy忽略空表格单元格,不会尝试剥离它们。


这样做会搞砸桌子。

< script type =" text / javascript" src =" xxx.js">< / script>
具有src属性的空脚本标记也是如此。


相同。整洁是愚蠢的,但不是那么愚蠢。

4)清空thead,tfoot标签
---------------------- -------------------------------------------
< table> ;
< thead>< tr>< td> head< / td>< / tr>< / thead>
< tfoot>< / tfoot>
< ; tbody>< tr>< td> body< / td>< / tr>< / tbody>
< / table>

整洁地发出空的警告tfoot元素,这是预期的因为< tfoot>绝不能空着。在这种情况下,我实际上会得到错误而不是警告,因为该文档不再符合有效的XHTML。
The warnings are also issued for documents that are considered valid
"XHTML 1.0 Strict" by the W3C Validator.
Tidy is a linter that has it''s own rules about how markup should be, no
relation to a validator that checks against the DTD.
A few examples:

1) empty <select> options
-----------------------------------------------------------------
<select name="x">
<option value=""></option>
<option value="foo">a foo</option>
<option value="bar">a bar</option>
</select>

[tidy] Warning: "trimming empty <option>"
That seems reasonable, the empty option should be removed.
I don''t know how I could avoid this warning. I don''t want to display any
text in the first option
Stop wanting that.
, and hacks like <option>&nbsp;</option> are not
acceptable.
Good.
<td class="c1"><span class="c2"></span> Some Text</td>
Constructs like this are sometimes used by our webdesigner in
combination with CSS. The span tag is technically empty, but the
stylesheet will cause an image to be displayed.
There is no way to prevent Tidy from trimming these empty elements.

Ideally the empty elements that Tidy strips should not be in the markup,
but in the real world there are no arguments why the above type of code
shouldn''t be used if used by a skilled coder.

Tidy is therefore over zealous in removing them, the solution is to do
to Tidy what it does to empty spans, get rid of it.
Tidy ignores empty table cells and does not try to strip them.
Doing so could screw up tables.
<script type="text/javascript" src="xxx.js"></script>
Same goes for empty script tags with src attributes.
Same. Tidy is stupid, but not that stupid.
4) Empty thead, tfoot tags
-----------------------------------------------------------------
<table>
<thead><tr><td>head</td></tr></thead>
<tfoot></tfoot>
<tbody><tr><td>body</td></tr></tbody>
</table>

Tidy issues a warning for the empty tfoot element, which is expected
because <tfoot> must never be empty. In this case I would actually
rather get an error instead of a warning, because the document does not
qualify as valid XHTML anymore.




如果你想测试有效性,请使用验证器,不要使用Tidy。


-

Spartanicus



Use a validator if you want to test for validity, don''t use Tidy.

--
Spartanicus


这篇关于整理修剪空标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆