有没有办法指定 RadEditor 中允许的 HTML 标签列表?例如,如果我只希望编辑器中允许以下标签:
b, u, i, strong, br, p
易于配置的东西,例如 ToolsFile.xml 文件中的属性。
我在任何地方都找不到这些信息。
您可以在此 Telerik 论坛主题中使用提供的自定义内容过滤器:
http://www.telerik.com/forums/restrict-to-table-editing-only
干得好:
<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>
你不能那样做。你可以做的是: