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

4

11

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.

Fordone answered 22/8, 2013 at 5:19 Comment(2)
Try new-empty-tags. "Unless you declare new tags, Tidy will refuse to generate a tidied file if the input includes previously unknown tags"Noblenobleman
new-empty-tags doesn't seem to be working for me.Anthraquinone
I
13

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.

Indre answered 2/10, 2015 at 16:51 Comment(1)
I also had the issue with the Python bidding. Passing {'drop-empty-elements': 0} option to tidy_document() solved it, thanks!Srinagar
E
3

try:

tidy.setTrimEmptyElements(false);
Earwig answered 2/10, 2015 at 15:45 Comment(0)
N
1

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

Nictitate answered 6/3, 2019 at 16:0 Comment(0)
S
0

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.

Sinclare answered 29/11, 2017 at 9:15 Comment(1)
unfortunately, it appears that (at least with some Tidy configurations), empty spans are removed too.Judah

© 2022 - 2024 — McMap. All rights reserved.