我正在使用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配置正确)

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

<b>My text</b>

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

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

我怎样才能做到这一点?