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.

      透传语义:原样返回输入,包括 null。与 withPolicy(com.wontlost.ckeditor.handler.HtmlSanitizer.SanitizationPolicy) / withSafelist(org.jsoup.safety.Safelist) 不同(后者把 null/空串归一为 "");这是有意为之,以保持 passthrough 的透明性。 标准调用路径在 ContentManager.getSanitizedValue 中已先行守卫 null,因此实际不会 把 null 传入此处。

      Returns:
      a passthrough sanitizer that returns its input verbatim (null in, null out)