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 content sanitizer.
Used to clean dangerous HTML tags and attributes before saving or displaying content.
Usage example:
// Use a predefined policy
editor.setHtmlSanitizer(HtmlSanitizer.withPolicy(SanitizationPolicy.STRICT));
// Custom sanitization logic
editor.setHtmlSanitizer(html -> {
// Remove all script tags
return html.replaceAll("<script[^>]*>.*?</script>", "");
});
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumSanitization policy. -
Method Summary
Modifier and TypeMethodDescriptiondefault HtmlSanitizerandThen(HtmlSanitizer other) Compose sanitizers (chain execution).static HtmlSanitizerA no-op sanitizer that passes content through unchanged.Sanitize HTML content.static HtmlSanitizerCreate a policy-based sanitizer.static HtmlSanitizerwithSafelist(org.jsoup.safety.Safelist safelist) Create a sanitizer with a custom safelist.
-
Method Details
-
sanitize
-
withPolicy
Create a policy-based sanitizer.- Parameters:
policy- the sanitization policy- Returns:
- a sanitizer instance
-
withSafelist
Create a sanitizer with a custom safelist.- Parameters:
safelist- the Jsoup safelist configuration- Returns:
- a sanitizer instance
-
andThen
Compose sanitizers (chain execution).- Parameters:
other- another sanitizer- Returns:
- a composed sanitizer
-
passthrough
A no-op sanitizer that passes content through unchanged.- Returns:
- a passthrough sanitizer
-