2016-11-28 6 views
0

Html.fromHtml成功したテキストをレンダリングし、しかしコメントし、私が持っているHTMLはコメント含まれていますHtml.fromHtmlショーはライン

<!-- p {margin-top:0;margin-bottom:0}--> 

をそして、このコメント行は、私のTextViewに表示されます。

enter image description here

コメント行が表示されないようにするにはどうすればよいですか?

コード

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; 
} 

答えて

0

私は手動でコメントを削除するには、正規表現を使用:

final Pattern pattern = Pattern.compile("<!--(.*?)-->"); 
final Matcher matcher = pattern.matcher(formattedContent); 

while (matcher.find()) 
{ 
    final String htmlComment = matcher.group(); 
    formattedContent = formattedContent.replace(htmlComment, ""); 
}