Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

htmltidy

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.

like image 358
frumbert Avatar asked Aug 22 '13 05:08

frumbert


People also ask

How do you remove empty tags?

Click in the tab "Logical Structure" on the button "Delete Empty Tags". Select which kind of empty tags shall be deleted. Confirm by clicking the button "OK". Done!

What is empty and non empty tags in HTML?

Empty: An element that contains no data but, rather, is an instruction to the browser to perform some action, such as force a line break or display an image. Empty elements in XHTML are terminated with a trailing slash, as in <br /> . Non-empty: An element that contains data.

What is empty tag for?

The tags that do not contain any closing tags are known as empty tags. Empty tags contain only the opening tag but they perform some action in the webpage. Syntax: <tag_name>

What is empty tag also called?

Empty tags are also known as void or unpaired tags.


Video Answer


3 Answers

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.

like image 138
Jim Avatar answered Sep 22 '22 19:09

Jim


try:

tidy.setTrimEmptyElements(false);
like image 28
Putti Tang Avatar answered Sep 24 '22 19:09

Putti Tang


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

like image 37
OlivierLarue Avatar answered Sep 22 '22 19:09

OlivierLarue