Hello again :)
This time I may have found a real bug.
Here is the code to reproduce:
package com.guillaumedelhumeau.htmlcleaner;
import org.htmlcleaner.CleanerProperties;
import org.htmlcleaner.HtmlCleaner;
import org.htmlcleaner.TagNode;
/**
* @version $Id: $
*/
public class Test
{
public static void main(String[] args)
{
String htmlContent = "<ul><p>Hello</p></ul>";
CleanerProperties props = new CleanerProperties();
props.setHtmlVersion(4);
HtmlCleaner cleaner = new HtmlCleaner(props);
try {
TagNode cleanedNode = cleaner.clean(htmlContent);
displayElement(cleanedNode, 0);
} catch (Exception e) {
throw new RuntimeException("Unhandled error when cleaning HTML", e);
}
}
private static void displayElement(TagNode tagNode, int level)
{
for (int i = 0; i < level; ++i) {
System.out.print("--");
}
System.out.println(tagNode.getName());
for (TagNode child : tagNode.getChildTagList()) {
displayElement(child, level + 1);
}
}
}
Results with HTML version 4:
html
--head
--body
----ul
------p
Results with HTML version 5:
props.setHtmlVersion(5);
html
--head
--body
----p
----ul
Now the
tag is outside the
The final objective is to get this code by using the serializer:
<html>
<head>
</head>
<body>
<ul>
<li> <!-- Adding the missing li here -->
<p>Hello</p>
</li>
</ul>
</body>
</html>
But it doesn't work anymore with HTML 5.
SF has eatten my message.
I repost the end of it:
Now the "p" tag is outside the "ul".
The final objective is to get this code by using the serializer:
But it doesn't work anymore with HTML 5.
Last edit: Guillaume Delhumeau 2016-01-05
Hmm, this is going to be an interesting challenge..!
I'm on the case...
OK I've got a fix for this. For some tags (UL, OL, TR) I try to first see if injecting an intervening tag (LI, TD) will fix things before trying moving the content to somewhere its allowed. I've set this behaviour using a "preferredChild" in TagInfo that is set by TagProvider just for those three tags.