【发布时间】:2019-01-08 08:50:01
【问题描述】:
我有一个使用 KendoEditor 实例的页面。编辑器的功能应该非常有限,并且只允许在其内容中包含strong、ul、li、ol 和p HTML 标签。每当我将整个网页粘贴到编辑器中时,它都会与该页面的所有 HTML 标记一起粘贴。
我尝试混合使用 KendoEditor 的 pasteCleanup 属性和正则表达式,如下所示:
pasteCleanup: {
css: true,
span: true,
msAllFormatting: true,
msConvertLists: true,
msTags: true,
keepNewLines: true,
custom: function (html) {
return html.replace(/<\/?(?!strong)(?!ul)(?!li)(?!ol)(?!p)\w*\b[^>]*>/, "");
}
},
但即使我在 pasteCleanup 上设置了 all: true,它仍然保留 span style="font-size: something"、字体和标题(h1、h2 ...等)标签。我还尝试在 KendoEditor 的粘贴事件上手动解析它:
paste: function(e) {
$(".text-editor").find("*").not("strong,ul,li,ol,p").each(function() {
$(this).replaceWith(this.innerHTML);
});
},
我尝试同时定位编辑器的textarea,以及包含显示文本的Iframe,但这绝对没有效果。我的假设是 paste 在内容被渲染之前触发。我还尝试了 pasteCleanup 的所有组合,您可以想象其中一些道具可能会相互冲突。有什么想法吗?
粘贴页面示例:https://html.nicole-wellinger.ch/schrift/txtgroesse.html
【问题讨论】:
标签: javascript jquery html kendo-ui kendo-editor