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.

@FunctionalInterface public interface HtmlSanitizer
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:
  • Method Details

    • sanitize

      String sanitize(String html)
      Sanitize HTML content.
      Parameters:
      html - the raw HTML content
      Returns:
      the sanitized safe HTML
    • withPolicy

      static HtmlSanitizer withPolicy(HtmlSanitizer.SanitizationPolicy policy)
      Create a policy-based sanitizer.
      Parameters:
      policy - the sanitization policy
      Returns:
      a sanitizer instance
    • withSafelist

      static HtmlSanitizer withSafelist(org.jsoup.safety.Safelist safelist)
      Create a sanitizer with a custom safelist.
      Parameters:
      safelist - the Jsoup safelist configuration
      Returns:
      a sanitizer instance
    • andThen

      default HtmlSanitizer andThen(HtmlSanitizer other)
      Compose sanitizers (chain execution).
      Parameters:
      other - another sanitizer
      Returns:
      a composed sanitizer
    • passthrough

      static HtmlSanitizer passthrough()
      A no-op sanitizer that passes content through unchanged.
      Returns:
      a passthrough sanitizer