addHTMLFilter

Availability: >= 3.0

Type: Object Method

Description: Registers a new HTML filter

Syntax:

editor.addHTMLFilterstring filtername, function function );

HTML filters are JavaScript functions that can be used to alter the HTML code generated by the editor.

They can be used to alter the format of code generated by the editor or to parse basic placeholder tags.

Parameters:

filtername
The name of the filter event which should call this function.

function
The JavaScript function that will perform the filter.

Example:

In the following example the first filter converts the template tag {site_url} to a URL when switching to design view so that images do not appear as broken images. The second filter converts the URL back into the {site_url} tag when generating source code.

var editor = WPro.editors['editorName'];

// Design view filter
editor.addHTMLFilter('design', function (editor, html) {
    return html.replace(/{site_url}/gi, "http://www.wysiwygpro.com");
});

// Source view filter
editor.addHTMLFilter('source', function (editor, html) {
    return html.replace(/http://www.wysiwygpro.com/gi, "{site_url}");
});

To add filters for template tags you should use the templateFilter plugin

See also:

triggerHTMLFilter