RadEditor - 如何指定允许的标签列表

时间:2013-08-29 06:18:47

标签: telerik radeditor

有没有办法在RadEditor中指定允许的HTML标签列表?例如,如果我只想在编辑器中允许以下标记:

b, u, i, strong, br, p

可轻松配置的内容,例如ToolsFile.xml文件中的属性。

我无法在任何地方找到这些信息。

2 个答案:

答案 0 :(得分:0)

你做不到。 你能做的是:

答案 1 :(得分:0)

您可以在此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>