在CKEditor中粘贴之前转换元素

时间:2016-07-25 04:34:39

标签: javascript ckeditor ckeditor4.x

我正在使用CKEditor和ACF。这样做很好,并过滤掉了我不想要的元素。我还选择将<span>用于粗体,斜体和下划线,将以下项添加到CKEditor的配置中:

...
coreStyles_bold: {
    element: 'span',
    overrides: 'strong',
    attributes: {'style': 'font-weight: bold;'}
},
coreStyles_italic: {
    element: 'span',
    overrides: 'em',
    attributes: {'style': 'font-style: italic;'}
},
coreStyles_underline: {
    element: 'span',
    overrides: 'u',
    attributes: {'style': 'text-decoration: underline;'}
}
...

对于那些感兴趣的人,这是我的ACF配置:

extraAllowedContent: '' +
    'p{font-weight,font-style,text-decoration,text-align};' +
    'a[!href];' +
    'span{font-weight,font-style,text-decoration,text-align};' +
    'br ul ol;' +
    'li{font-weight,font-style,text-decoration,text-align};' +
    'gallery vid attachment[trix-id](*);' +
    'table tr td th;' +
    'div(trix-inserting,attachment,break)[contenteditable]'

(其中很多是针对这个特定的应用程序,但我在此处发布以显示ACF配置正确)

我遇到的问题是,当复制粗体文本时,它的结构通常如下:

<b>My text</b>

但是,我的ACF配置不允许<b>标记,因此标记会被删除,因此会粘贴非粗体文本。

我想要的是扫描所有被粘贴元素的方法(在触发ACF之前),并更改<b><strong><em>,{ {1}},<u>以及其他任何粗体,斜体和下划线标记,以及配置中显示的样式(上图)。

我该怎么做?

0 个答案:

没有答案