简体   繁体   English

CKEditor ::按自定义标记包装内容

[英]CKEditor :: Wrap content by custom tag

I wrote a plugin for CKEditor.I want to wrap contents of editor between div with custom style. 我为CKEditor写了一个插件。我想用自定义样式包装div之间的编辑器内容。

In this case I used dialog for style div tag. 在这种情况下,我使用了dialog样式div标签。 How can I wrap contents of editor inside 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: [{ ...

Ok I found the solution : 好的我找到了解决方案:

first in config.js put the below line : 首先在config.js输入以下行:

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

see here and here . 看到这里这里

then in onOk function do this : 然后在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: [{ ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM