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

5.1k Views Asked by At

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.

4

There are 4 best solutions below

1
On

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

0
On

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

0
On

try:

tidy.setTrimEmptyElements(false);
1
On

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.