html tidy removes empty tags, such as <i class='icon-foo'></i>

感情迁移 提交于 2019-12-23 07:25:46

问题


I have documents with lots of font-awesome icons in them, which are embedded using <i class='icon-somename'></i>. An empty i tag... HTML Tidy removes them. I've set drop-empty-paras to false, but it still removes this tag. The documentation has not been of any help in resolving the matter, perhaps someone here knows?

I think it's absurd to have to break all my icons by adding content inside the tag just so tidy can be run then remove all the content again afterwards. But so far that has been the only suggestion I've found.


回答1:


I had the same problem in the Tidy2 plugin for Notapad++. It was removing some empty tags that had nothing but a bootstrap class on them, like <span class="caret"></span>. I fixed it by using drop-empty-elements: no in the config file.

This is an old question, and the documentation you linked to doesn't show that option as being valid, so probably you were using original Tidy and the option was added in Tidy2.

Just figured, since my initial search landed me here, and I didn't find the answer on this post and had to figure it out myself, maybe this answer will help someone else, even if it's too late to help the OP.




回答2:


try:

tidy.setTrimEmptyElements(false);



回答3:


The real answer, of course, is not to use the ludicrous empty element but to use span. It beggars belief that the authors of the otherwise excellent FA would recommend using bogus markup like this.




回答4:


If using it from a CLI environment you can override the config :
tidy --drop-empty-elements no "/path/to/file.html"



来源:https://stackoverflow.com/questions/18372185/html-tidy-removes-empty-tags-such-as-i-class-icon-foo-i

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!