Reputation: 5480
Html.fromHtml
successfully renders the text, however, the HTML which I have contains a comment:
<!-- p {margin-top:0;margin-bottom:0}-->
And this comment line is showing in my TextView
:
How do I prevent the comment line from showing?
Code
public String getFormattedBody()
{
String formattedContent;
if (contentType.equalsIgnoreCase("html"))
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
{
formattedContent = Html.fromHtml(content, Html.FROM_HTML_MODE_LEGACY).toString();
}
else
{
formattedContent = Html.fromHtml(content).toString();
}
}
else
{
return content;
}
return formattedContent;
}
Upvotes: 1
Views: 123
Reputation: 5480
I used a regular expression to manually remove the comment:
final Pattern pattern = Pattern.compile("<!--(.*?)-->");
final Matcher matcher = pattern.matcher(formattedContent);
while (matcher.find())
{
final String htmlComment = matcher.group();
formattedContent = formattedContent.replace(htmlComment, "");
}
Upvotes: 0