goog.html.sanitizer.HtmlSanitizer
Provided By | |
---|---|
Extends |
Creates an HTML sanitizer.
new HtmlSanitizer( opt_builder )
Parameters |
|
---|
Instance Methods
this.createElementWithoutAttributes( originalElement ) → (Element|null)
(Element|null)
Creates a new element from the original element. This function should only either create a new element (optionally changing the tag name from the original element) or return null to prevent the entire subtree from appearing in the output. Note that TEMPLATE tags and their contents are automatically dropped, and this function is not called to decide whether to keep them or not.
Overrides | |||||
---|---|---|---|---|---|
Parameters |
| ||||
Returns |
|
this.createTextNode( originalNode ) → (Text|null)
(Text|null)
Creates a new text node from the original text node, or null if the node should not be copied over to the new tree.
Overrides | |||||
---|---|---|---|---|---|
Parameters |
| ||||
Returns |
|
this.preProcessHtml( html ) → string
string
this.processElementAttribute( element, attribute ) → (string|null)
(string|null)
Returns the new value for an attribute, or null if the attribute should be dropped.
Overrides | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
| ||||||||
Returns |
|
this.processRoot( newRoot ) → void
void
Creates the root SPAN element for the new tree. This function can be
overridden to add attributes to the tag. Note that if any attributes are
added to the element, then processToString
will not strip it from the
generated string to preserve the attributes.
Overrides | |||||
---|---|---|---|---|---|
Parameters |
|
this.processToString( html ) → string
string
this.processToTree( html ) → HTMLSpanElement
HTMLSpanElement
Parses an HTML string and walks the resulting DOM forest to apply the transformation function and generate a copy of the forest. Returns the forest wrapped in a common SPAN parent, so that the result is always a tree.
Defined by | |||||
---|---|---|---|---|---|
Parameters |
| ||||
Returns |
|
this.sanitize( unsanitizedHtml ) → goog.html.SafeHtml
goog.html.SafeHtml
Parses the DOM tree of a given HTML string, then walks the tree. For each element, it creates a new sanitized version, applies sanitized attributes, and returns a SafeHtml object representing the sanitized tree.
Parameters |
| ||||
---|---|---|---|---|---|
Returns |
|
this.sanitizeToDomNode( unsanitizedHtml ) → HTMLSpanElement
HTMLSpanElement
Parses the DOM tree of a given HTML string, then walks the tree. For each element, it creates a new sanitized version, applies sanitized attributes, and returns a span element containing the sanitized content. The root element might define a class name to restrict the visibility of CSS rules contained in tree.
Parameters |
| ||||
---|---|---|---|---|---|
Returns |
|
Static Functions
HtmlSanitizer.sanitize( unsanitizedHtml ) → goog.html.SafeHtml
goog.html.SafeHtml
Sanitizes a HTML string using a sanitizer with default options.
Parameters |
| ||||
---|---|---|---|---|---|
Returns |
|