RadEditor - How to specify a list of allowed tags

1.5k views Asked by At

Is there a way to specify a list of HTML Tags allowed inside a RadEditor? Like for example, if I only want the following tags allowed in the Editor:

b, u, i, strong, br, p

Something that is easily configurable, like the properties in the ToolsFile.xml file.

I couldn't find this information anywhere.

2

There are 2 answers

0
rdmptn On BEST ANSWER

You can't do that. What you can do is:

0
Rumen Jekov On

You can use the provided custom content filter in this Telerik forum thread:

http://www.telerik.com/forums/restrict-to-table-editing-only

Here you go:

<script type="text/javascript">
function OnClientLoad(editor, args) {
   editor.get_filtersManager().add(new AllowedTagsFilter());
}
AllowedTagsFilter = function() {
AllowedTagsFilter.initializeBase(this);
this.set_isDom(false);
this.set_enabled(true);
this.set_name("AllowedTagsFilter");
this.set_description("Strip the unwanted tags from RadEditor");
}
 AllowedTagsFilter.prototype =
 {
   getHtmlContent: function(content) {
   return this._removeHtmlTags(content);
 },
getDesignContent: function(content) {
   return this._removeHtmlTags(content);
},
 _removeHtmlTags: function(initContent) {
   var cleanContent;
   //Perform necessary REGEX replacement to remove unsupported HTML tags
   //Supported Reporting HTML tags: FONT, STRONG, B, EM, I, U, A, OL, UL, LI, DIV, SPAN, P, BR, CENTER
   //HTML must be XHTML valid, too, but Editor already provides that filter
   //Following REGEX will remove all HTML tags EXCEPT those expliclitly listed
   cleanContent = initContent.replace(new RegExp("<(?!\/?(font|strong|b|em|(i(?!mg))|u|a|ol|ul|li|div|span|p|br|center)(?=>|\s?.*>))\/?.*?>", "ig"), "");
   return cleanContent;
 }
}
AllowedTagsFilter.registerClass('AllowedTagsFilter', Telerik.Web.UI.Editor.Filter);
</script>
<telerik:RadEditor runat="server" OnClientLoad="OnClientLoad" ID="RadEditor1">
<Content>sample content test <br/> test</Content>
</telerik:RadEditor>