How to reproduce:
import org.htmlcleaner.CleanerProperties;
import org.htmlcleaner.HtmlCleaner;
import org.htmlcleaner.TagNode;
public class Test
{
public static void main(String[] args)
{
String htmlContent = "<font face=\"Arial\" size=\"3\" color=\"red\">This is some text!</font>";
CleanerProperties props = new CleanerProperties();
props.setOmitUnknownTags(true);
HtmlCleaner cleaner = new HtmlCleaner(props);
try {
TagNode cleanedNode = cleaner.clean(htmlContent);
for (TagNode tagNode : cleanedNode.getAllElements(true)) {
System.out.println(tagNode);
}
} catch (Exception e) {
throw new RuntimeException("Unhandled error when cleaning HTML", e);
}
}
}
Results with HTMLCleaner 2.10:
head
body
font
Results with HTMLCleaner since 2.11:
head
body
If I do
props.setOmitUnknownTags(false);
Then the "font" tag comes back. But I guess this tag should not be "unknown".
Thanks,
Guillaume Delhumeau - XWiki
Hi Guillaume,
The FONT tag was completely removed from the HTML5 specification, so its not in Html5TagProvider. If you switch to specifying HTML4 mode then its included, e.g.:
... but of course you then miss out on the added HTML5 tags.
Alternatively you can create a custom TagProvider including the parts of HTML4 you want to retain.
S
I see. Thanks for the explanations.
My use-case was to catch these font tags to replace them by other tags.
I am going to see how I can do that now, maybe using the TagProvider you have mentioned.
Thanks,
Guillaume
Last edit: Guillaume Delhumeau 2016-01-04
There is also an example specifically to replace FONT in the tag transformation documentation here:
http://htmlcleaner.sourceforge.net/parameters.php#transform
In that case it replaces it with a span and a style attribute.
(The relevant Java code for that transformation example is on http://htmlcleaner.sourceforge.net/javause.php)
I have tried to create a custom TagProvider, but infortunatly CleanerProperties#setTagInfoProvider() is private.
You can pass in a TagProvider implementation in the HtmlCleaner constructor e.g. new HtmlCleaner(myTagProvider, myProperties)
My bad. Sorry for that noise.
Thanks for your help. I think you can close the issue.