CleanHtml
HTML cleaner with extra post cleaning that makes it suitable for cleaning input typed and pasted into contenteditable editors.
Constructor Summary
Public Constructor | ||
public |
|
Member Summary
Public Members | ||
public |
options: * |
Method Summary
Public Methods | ||
public |
Clean the provided html. |
|
public |
paste(originalHtml: *, pastedHtml: *): * This function takes two html-blobs, |
|
public |
Called at the end of CleanHtml#clean after performing the default cleaning. |
|
public |
Called at the beginning of CleanHtml#clean before performing the default cleaning. |
Public Constructors
public constructor source
Public Members
public options: * source
Public Methods
public clean(html: string, preservePasteMarker: *): string source
Clean the provided html.
Params:
Name | Type | Attribute | Description |
html | string | The HTML to clean. |
|
preservePasteMarker | * | {boolean} if true, leave the tag with |
public paste(originalHtml: *, pastedHtml: *): * source
This function takes two html-blobs, originalHtml
is the original text, pastedHtml
is text to be inserted in
originalHtml
.
The original html-blob should contain a 'marker-element' determining where to paste the given pastedHtml
. This
marker element should have the data-attribute data-ievv-paste-marker
. If multiple marker-elements are present,
an error will be logged, and pastedHtml
will be inserted at the first one.
Note: result from these examples will be cleaned once more using default cleaner, so if the cleaner is configured to wrap standalone text the standalone text in e.g. example 1 would be wrapped in some block-level tag before returning.
Params:
Name | Type | Attribute | Description |
originalHtml | * | ||
pastedHtml | * |
Return:
* |
Example:
originalHtml: <p>Hello world! I am some text</p>
pastedHtml: awesome
result: <p>Hello world! I am some text</p>awesome
originalHtml: <p>Hello world! I am some text</p>
pastedHtml: <strong>awesome</strong>
result: <p>Hello world! I am some text</p><strong>awesome</strong>
originalHtml: <p>Hello world! I am some <span data-ievv-paste-marker></span>text</p>
pastedHtml: awesome
result: <p>Hello world! I am some awesome<span data-ievv-paste-marker></span>text</p>
originalHtml: <p>Hello world! I am some <span data-ievv-paste-marker></span>text</p>
pastedHtml: <strong>awesome</strong>
result: <p>Hello world! I am some <strong>awesome<span data-ievv-paste-marker></span></strong>text</p>
originalHtml: <p>Hello world! I am some <span data-ievv-paste-marker></span>text</p>
pastedHtml: <p>awesome</p>
result: <p>Hello world! I am some </p>
<p>awesome<span data-ievv-paste-marker></span></p>
<p>text</p>
originalHtml: <p>Hello world! I am <strong>some <span data-ievv-paste-marker></span>text</strong></p>
pastedHtml: <strong>awesome</strong>
result: <p>Hello world! I am <strong>some </strong><strong>awesome<span data-ievv-paste-marker></span></strong><strong>text</strong></p>
public postClean(html: string): string source
Called at the end of CleanHtml#clean after performing the default cleaning.
Subclasses can override this to perform additional cleaning post-cleaning.
Params:
Name | Type | Attribute | Description |
html | string | The HTML to post-clean. |
public preClean(html: string): string source
Called at the beginning of CleanHtml#clean before performing the default cleaning.
Subclasses can override this to perform additional cleaning pre-cleaning.
Params:
Name | Type | Attribute | Description |
html | string | The HTML to pre-clean. |