I am trying to use JTidy (jtidy-r938.jar) to sanitize an input HTML string, but I seem to have problems getting the default settings right. Often strings such as "hello world" end up as "helloworld" after tidying. I wanted to show what I'm doing here, and any pointers would be really appreciated:
Assume that rawHtml
is the String containing the input (real world) HTML. This is what I'm doing:
Tidy tidy = new Tidy();
tidy.setPrintBodyOnly(true);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
tidy.parse(new StringReader(rawHtml), ps);
return baos.toString("UTF8");
First off, does anything look fundamentally wrong with the above code? I seem to be getting weird results with this.
For example, consider the following input:
<p class="MsoNormal" style="text-autospace:none;"><font color="black"><span style="color:black;">???</span></font><b><font color="#7f0055"><span style="color:#7f0055;font-weight:bold;">private</span></font></b><font color="black"><span style="color:black;"> String parseDescription</span></font><font>
The output is:
<p class="MsoNormal" style="text-autospace:none;"><font color=
"black"><span style="color:black;"> </span></font>
<b><font color="#7F0055"><span style=
"color:#7f0055;font-weight:bold;">private</span></font></b><font
color="black"><span style="color:black;">String
parseDescription</span></font></p>
So,
"public String parseDescription" becomes "publicString parseDescription"
Thanks in advance!