Home Manual Reference Source
import CleanHtml from 'ievv_jsbase/lib/html/CleanHtml'
public class | source

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(html: string, preservePasteMarker: *): string

Clean the provided html.

public

paste(originalHtml: *, pastedHtml: *): *

This function takes two html-blobs, originalHtml is the original text, pastedHtml is text to be inserted in originalHtml.

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:

NameTypeAttributeDescription
html string

The HTML to clean.

preservePasteMarker *

{boolean} if true, leave the tag with data-ievv-paste-marker attribute.

Return:

string

The cleaned HTML.

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:

NameTypeAttributeDescription
originalHtml *
pastedHtml *

Return:

*

Example:

1 - pasting unformatted text without marker:
originalHtml: <p>Hello world! I am some text</p>
pastedHtml: awesome
result: <p>Hello world! I am some text</p>awesome
2 - pasting formatted text without marker:
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>
3 - pasting unformatted text with marker:
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>
4 - pasting formatted text with marker:
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>
5 - pasting block tag with marker:
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>
6 - pasting formatted text in formatting with marker:
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:

NameTypeAttributeDescription
html string

The HTML to post-clean.

Return:

string

The cleaned HTML. Defaults to returning the provided html unchanged.

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:

NameTypeAttributeDescription
html string

The HTML to pre-clean.

Return:

string

The pre-cleaned HTML. Defaults to returning the provided html unchanged.