Options
All
  • Public
  • Public/Protected
  • All
Menu

HTML sanitizer class provides two features:

  1. Convert global CSS to inline CSS
  2. Sanitize an HTML document, remove unnecessary/dangerous attribute/nodes

Hierarchy

  • HtmlSanitizer

Index

Constructors

constructor

Methods

convertGlobalCssToInlineCss

  • convertGlobalCssToInlineCss(rootNode: ParentNode): void

exec

  • exec(html: string, convertCssOnly?: boolean, currentStyles?: StringMap): string
  • deprecated

    Use HtmlSanitizer.convertGlobalCssToInlineCss() and HtmlSanitizer.sanitize() instead Sanitize HTML string This function will do the following work:

    1. Convert global CSS into inline CSS
    2. Remove dangerous HTML tags and attributes
    3. Remove useless CSS properties

    Parameters

    • html: string

      The input HTML

    • Optional convertCssOnly: boolean
    • Optional currentStyles: StringMap

      Current inheritable CSS styles

    Returns string

sanitize

  • sanitize(rootNode: Node, currentStyles?: StringMap): string
  • Sanitize an HTML element, remove unnecessary or dangerous elements/attribute/CSS rules

    Parameters

    • rootNode: Node

      Root node to sanitize

    • Optional currentStyles: StringMap

      Current CSS styles. Inheritable styles in the given node which has the same value with current styles will be ignored.

    Returns string

Static convertInlineCss

  • convertInlineCss(html: string, additionalStyleNodes?: HTMLStyleElement[]): string
  • deprecated

    Use new HtmlSanitizer().convertGlobalCssToInlineCss() instead Convert global CSS to inline CSS if any

    Parameters

    • html: string

      HTML source

    • Optional additionalStyleNodes: HTMLStyleElement[]

      (Optional) additional HTML STYLE elements used as global CSS

    Returns string

Static sanitizeHtml

Generated using TypeDoc