CKeditor 4.8 不删除粘贴样式

CKeditor 4.8 not removing styles on paste

我们最近将我们的 CKeditor 升级到 4。(这是一个很大的飞跃,我认为我们在 4.3 上)以及当用户粘贴代码时,编辑器如何不自动删除样式,特别是字体和文本颜色。我的配置中确实有 forcePasteAsPlainText : true,但我可以可靠地重现粘贴在保留字体颜色(例如:红色)的文本中,就像在电子邮件中一样。我怎样才能使粘贴的所有文本都去掉 HTML 样式?

我假设当您使用从 Word 插件粘贴时会发生这种情况,因为根据 forcePasteAsPlainText 信息:

Whether to force all pasting operations to insert on plain text into the editor, losing any formatting information possibly available in the source text.

Note: paste from word (dialog) is not affected by this configuration.

所以,我会使用 forcePasteAsPlainText 并禁用此插件:

forcePasteAsPlainText : true,
removePlugins: 'pastefromword'

请检查您使用的是哪个版本的CKEditor。它可以在 ckeditor/CHANGES.md 文件的顶部找到。如果您使用的不是最新的 4.8.0,请升级。

虽然 forcePasteAsPlainText 在早期版本中存在一些问题,但设置该选项并粘贴 HTML 应该会在最新的编辑器 4.8.0 中按预期过滤它。

如果您还想清除所有 MS Word 格式,那么就像@Wizard 写的那样,您可以删除 pastefromword 插件。或者,如果您只想删除某些样式,可以使用 afterPasteFromWord 事件,您可以在其中粘贴 HTML 到 event.data.dataValue 并按照您喜欢的方式进行更改。