Menu

#164 Font tag is not known anymore

v2.19
closed-fixed
nobody
None
5
2017-02-06
2016-01-04
No

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

Discussion

  • Scott Wilson

    Scott Wilson - 2016-01-04

    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.:

    cleaner.getProperties().setHtmlVersion(4);
    

    ... 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

     
  • Guillaume Delhumeau

    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
  • Scott Wilson

    Scott Wilson - 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.

     
  • Scott Wilson

    Scott Wilson - 2016-01-04

    (The relevant Java code for that transformation example is on http://htmlcleaner.sourceforge.net/javause.php)

     
  • Guillaume Delhumeau

    I have tried to create a custom TagProvider, but infortunatly CleanerProperties#setTagInfoProvider() is private.

     
  • Scott Wilson

    Scott Wilson - 2016-01-04

    You can pass in a TagProvider implementation in the HtmlCleaner constructor e.g. new HtmlCleaner(myTagProvider, myProperties)

     
  • Guillaume Delhumeau

    My bad. Sorry for that noise.

     
  • Guillaume Delhumeau

    Thanks for your help. I think you can close the issue.

     
  • Scott Wilson

    Scott Wilson - 2017-02-06
    • Group: v 2.7 --> v2.19
     
  • Scott Wilson

    Scott Wilson - 2017-02-06
    • status: open --> closed-fixed
     

Log in to post a comment.

Monday.com Logo