[英]jQuery KendoEditor not stripping pasted HTML
我有一個頁面,我在其中使用了 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 ,但這絕對沒有效果。 我的假設是在內容渲染之前粘貼會觸發。 我還嘗試了幾乎所有pasteCleanup的組合,你可以想象這些道具中的一些可能會相互沖突。 任何的想法?
粘貼頁面示例: https : //html.nicole-wellinger.ch/schrift/txtgroesse.html
您忘記了一個小而重要的細節: JavaScript修飾符 g
。 您可能還需要考慮i
是否區分大小寫。
對我來說這是它的工作
pasteCleanup: {
custom: function (html)
{
html = html.replace(/<\s*br\/*>/gi, '');
html = html.replace(/<\s*a.*href="(.*?)".*>(.*?)<\/a>/gi, " $2 (Link - $1) ");
html = html.replace(/<\s*\/*.+?>/ig, '');
html = html.replace(/ {2,}/gi, '');
html = html.replace(/\n+\s*/gi, '');
html = html.replace(" ", '');
html = html.replace(/<.*?>/g, '');
return html;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.