CKEditor内联选择换行

CKEditor Inline selection wrapping

本文关键字:换行 选择 CKEditor      更新时间:2023-09-26

我正在寻找一种方法来添加一个具有属性的内联span元素的选择。其中困难的部分是让它与传递多个块级元素的选择一起工作。

我在StyleCombobox的源代码中找到了这一行。

var style = styles[ value ],
elementPath = editor.elementPath();
editor[ style.checkActive( elementPath ) ? 'removeStyle' : 'applyStyle' ]( style );

这种方式已经在多个块级元素上工作了。

唯一的事情是,我想把属性应用到围绕不同块级元素的多个选择的span上,而不是应用样式元素。

有谁知道这是怎么做的吗?

我用这个作为解决方案。确实可以设置属性和元素类型。这在api中没有定义。我在CKEditor 3.0 api(旧版本)中发现了这个

var style = new CKEDITOR.style({attributes: {name:"changed"}});
editor.applyStyle(style);

您的问题的最新解决方案。

获取选定文本:

editor.getSelection().getSelectedText();

设置标签和属性

editor.applyStyle(new CKEDITOR.style({
        element : 'span', 
        attributes : {'class':'YourClass','data-Otherattr':'otherattrvalue'}, 
        style : {'background-color':'gray'} 
    });
);