
ckeditor5 已彻底弃用全局 `ckeditor` 对象,其配置方式与旧版 ckeditor4 截然不同;需通过 `htmlsupport` 插件等新机制实现 html 元素、属性、样式等白名单控制。
CKEditor5 是一个完全重写的现代富文本编辑器,不兼容 CKEditor4 的 API。你遇到的 Uncaught ReferenceError: CKEDITOR is not defined 错误,根本原因在于:CKEDITOR.replace() 是 CKEditor4 的初始化方法,而你引入的是 CKEditor5 的 CDN(/ckeditor5/38.1.1/classic/ckeditor.js),其全局对象是 ClassicEditor,而非 CKEDITOR——后者在 CKEditor5 中已被完全移除。
✅ 正确配置方式(CKEditor5)
CKEditor5 采用插件化架构,若需支持自定义 HTML(如
? 关键说明
- htmlSupport.allow 是声明式白名单:相比 CKEditor4 的正则式 extraAllowedContent,CKEditor5 要求显式声明允许的元素、属性、类名和样式规则,更安全、更可控。
-
细粒度控制示例(推荐生产环境使用):
htmlSupport: { allow: [ { name: 'style' }, // 仅允许
