首页 文章

CKEditor自定义ACF禁用所有插件

提问于
浏览
1

我试图在我的ck编辑器中设置一个允许内容的明确列表,但似乎我的列表中没有足够的包容性,因为几乎所有的插件都被禁用了 . 如果我将ACF设置回auto(删除allowedContent),则所有插件都会返回 . 这是config.js中的allowedConent

config.allowedContent = 
{
     h1: true,
     h2: true,
     h3: true,
     'span, p, ul, ol, li,': {
         styles: 'color, margin-left, margin-right, font-size'
     },
     'a[!href,target,name]': true,
     b: true,
     u: true,
     i: true,
}

然而,似乎启用的唯一按钮是粗体,下划线和斜体 . 我试图找出为什么我的其他插件无法正常工作 . 例如,链接插件具有以下内容:

var allowed = 'a[!href]',
required = 'a[href]';

// Add the link and unlink buttons.
editor.addCommand( 'link', new CKEDITOR.dialogCommand( 'link', {
    allowedContent: allowed,
    requiredContent: required
} ) );
editor.addCommand( 'anchor', new CKEDITOR.dialogCommand( 'anchor', {
    allowedContent: 'a[!name,id]',
    requiredContent: 'a[name]'
} ) );

正如您所看到的,我已经定义了必要的属性(使用href和名称锚定),但按钮没有显示!通过打印出CKEDITOR.instances [“editor-1”] . filter.allowedContent,我已经验证了我的语法是正确的,它显示了我期待的对象 . 我也尝试添加一些常见的元素,比如看看是否添加其中一个带回来的插件,但事实并非如此 . 那我错过了什么?

1 回答

  • 1

    好吧,我似乎在混合我的对象语法和我的字符串语法 . 一旦我纠正了这个,锚和字体大小按钮就开始出现了 . 以下是我到目前为止的情况:

    config.allowedContent = 
    {
         h1: true,
         h2: true,
         h3: true,
         a: {
            attributes: ['!href','target','name']
         }, 
         b: true,
         u: true,
         i: true,
         // font-size
         span: {
             styles: { 'font-size': '#(size)' },
             overrides: [ { element :'font', attributes: { 'size': null } } ]
         }
    }
    

    我仍然需要弄清楚font-color和其他一些正确的定义,但这只是检查插件代码并看到他们期望的问题 .

相关问题