Interface HtmlSanitizer
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
HTML 内容清理器。
用于在保存或显示内容前清理危险的 HTML 标签和属性。
使用示例:
// 使用预定义策略
editor.setHtmlSanitizer(HtmlSanitizer.withPolicy(SanitizationPolicy.STRICT));
// 自定义清理逻辑
editor.setHtmlSanitizer(html -> {
// 移除所有 script 标签
return html.replaceAll("<script[^>]*>.*?</script>", "");
});
- See Also:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptiondefault HtmlSanitizerandThen(HtmlSanitizer other) 组合清理器(链式执行)static HtmlSanitizer不进行任何清理的清理器清理 HTML 内容static HtmlSanitizer创建基于策略的清理器static HtmlSanitizerwithSafelist(org.jsoup.safety.Safelist safelist) 创建自定义白名单的清理器
-
Method Details
-
sanitize
-
withPolicy
创建基于策略的清理器- Parameters:
policy- 清理策略- Returns:
- 清理器实例
-
withSafelist
创建自定义白名单的清理器- Parameters:
safelist- Jsoup 白名单配置- Returns:
- 清理器实例
-
andThen
组合清理器(链式执行)- Parameters:
other- 另一个清理器- Returns:
- 组合后的清理器
-
passthrough
-