CKEditor :: 通过自定义标签包装内容

CKEditor :: Wrap content by custom tag

我为 CKEditor.I 写了一个插件,想用自定义样式在 div 之间包装编辑器的内容。

在这种情况下,我使用 dialog 作为样式 div 标签。如何将编辑器的内容包装在 div 中:

  onOk: function() {
            var dialog = this;
            var color = dialog.getValueOf('tab1', 'color');
            // other styles
            var tag= '<div style="';
            tag += 'color:' + color + ';';
            // ... other styles
            tag += '">';
            // tag += contents ;
            tag += "</div>";
            editor.insertHtml(tag)
        },
        contents: [{ ...

好的,我找到了解决方案:

首先在 config.js 中放置以下行:

config.allowedContent = 'div{*}'; // this is important

参见 here and here

然后在 onOk 函数中执行此操作:

   onOk: function() {
            contents = editor.document.getBody().getHtml(); // get the content of CKEditor
            var dialog = this;
            var color = dialog.getValueOf('tab1', 'color');
            // other styles
            var tag= '<div style="';
            tag += 'color:' + color + ';';
            // ... other styles
            tag += '">';
            tag += contents ;
            tag += "</div>";
            editor.setData(tag);
        },
        contents: [{ ...