【发布时间】:2017-01-03 16:06:41
【问题描述】:
使用 Jsoup clean 是否可以转换此字符串:
Here is some <b>important</b> stuff that can't have
<script>javascript</script> or the following embed tag
<embed src="helloworld.swf" type="application/vnd.adobe.flash-movie"> movie
in the output
到这里:
Here is some <b>important</b> stuff that can't have
<script>javascript</script> or the following embed tag
<embed src="helloworld.swf" type="application/vnd.adobe.flash-movie">
movie in the output
所以它呈现
这里有一些重要不能有的东西 或以下嵌入标签
粗体标签是允许的,但脚本和嵌入标签的分隔符从 < > 更改为 &lt; and &gt;,因此它们被视为文本而不是真正的 html 元素。
完成此操作需要哪些设置?我有:
private static String limitHtml(String value) {
String result = value;
if (value != null && !value.isEmpty()) {
Document.OutputSettings settings = new Document.OutputSettings();
settings.prettyPrint(false);
// what other settings ???
Whitelist whitelist = Whitelist.none().addTags(ALLOWED_HTML_TAGS);
whitelist.addAttributes(":all", ALLOWED_HTML_ATTRIBUTES);
result = Jsoup.clean(value, "", whitelist, settings);
}
return result;
}
如果 Jsoup 没有,是否有类似的 Java 库可以完成此任务。
【问题讨论】: