|
Content Filters
Filters are small code snippets, which are
called in a sequence to process the editor content, when the mode (html /
design / preview) is changed. Basically, the editor content is supplied to
the filter chain and each filter gets a chance to modify it. Currently
the available filters correspond to the following editor properties:
1. StripAbsoluteAnchorPaths - IE converts
all relative URLs to absolute and this property allows to control/revert
the process 2. StripAbsoluteImagesPaths - IE converts
all relative URLs to absolute and this property allows to control/revert
the process 3. ConvertTagToLower - (Under IE) converts
tag names to lower case, which is XHTML compliant 4. ConvertFontToSpan - convert the found font tags to span tags 5.
AllowScripts - (false by default) - allows for (CLIENT or
SERVER) script tags to be inserted/submitted with the editor. Eases the
developer's job against script attacks. Note: This
property replaces the deprecated AllowServerScripts
property.
There is also a sixth unconditional filter that adds quotes
around tag attributes (e.g. width = "25"), as IE strips quotes
automatically when the editor content is requested.
There are two additional properties, used for fine-tuning
the behavior of the StripAbsoluteAnchorPaths and
StripAbsoluteImagesPaths
filters: AnchorPathToStrip ImagesPathToStrip They
are useful in some rare cases when the local absolute path to be stripped
cannot be detected properly and has to be specified manually.
The other filters can be modified, detached and re-attached
if necessarily on the client using the Filter API.
Implementing Custom
Filters
This example has one �ustom Filter implemented. It modifies
the editor content so that in HTML mode it is presented with capital
letters and in Design mode it is shown in all-small letters. This is a
fairly simplistic and unrealistic scenario, but it demonstrates what is
necessary for createing and "hooking" a filter to the editor. In real-life
scenario the filter would likely employ a number of regular expressions of
various complexity that will make the necessary changes to the
content.
The two steps for implementing a Custom Filter are:
1. Create a javascript function/class that implements one or
more of the three filter methods: �
GetDesignContent (Called when the editor is switched from
some other mode to DESIGN mode) �
GetHtmlContent (Called when the editor is switched from
some other mode to HTML mode) �
GetPreviewContent (Called when the editor is switched
from some other mode to PREVIEW mode)
2. Register the filter with the editor. The best way to do
it is to register a OnClientLoad function that instantiates the filter and
adds it to the filter manager.
|