CKEditor- acf内容过滤器/允许的内容不按预期工作

CKEditor- acf content filter/ allowed content not working as expected

本文关键字:工作 acf 过滤器 CKEditor-      更新时间:2023-09-26

这是一个集两个问题于一体的问题:

Q1)我有以下代码:

http://jsfiddle.net/anik786/L8kb4nes/1/

下面是HTML:

<form action="javascript:void(0)">
    <textarea id="editor1" name="editor1" cols="80" rows="10">
        Example Text
    </textarea>
    <button id="btnOutput">Get Data</button>
</form>
<div id="output"></div>

和JS:

 var editor = CKEDITOR.replace('editor1', {
        allowedContent:
        'h1 h2 h3 p blockquote strong em;' +
        'a[!href];' +
        'img(left,centre, right)[!src,alt,width,height];' +
        'figure figcaption;' +
        'table tr th td caption;' +
        'span{!font-family};' +
        'span{!color};' +
        'span(!marker);' +
        'span(!math-tex);' +
        'del ins'
    });
$("#btnOutput").on("click", function(){
    $('#output').text(editor.getData());
});

如果我切换到源代码模式并输入一些无效的内容,比如:

Hi

然后返回到所见即所得,然后单击"获取数据"按钮,然后输出中的h4标签变为p标签。在返回到源模式时也会验证这一点。这是预期的,因为h4不在允许的内容中。

但是,如果我切换到源模式并写入

Hi

然后直接点击"获取数据"按钮(即不切换回所见即所得),h4标签出现在输出上。

我该如何解决这个问题?

Q2)内容过滤器似乎不适用于脚本标记。像

<script src="bad.js></script>

来回切换wywig时,此标签不会消失。为什么?

我刚刚找到了一个'ok '的方法来实现这个。

我将输出按钮代码更改为:

CKEDITOR.instances.editor1.setMode( 'wysiwyg', function() {
            $('#output').text(editor.getData());
        } ); 

这实际上迫使编辑器更改为wyswig模式,然后获取数据。但是,我希望避免这种情况,因为如果用户的编辑器只是自动改变模式,这可能会激怒用户!