我已经在 Django 站点的管理后端实现了标准 CKEditor 配置。 settings.py 中默认的 CKEDITOR_CONFIGS 为:
CKEDITOR_CONFIGS = {
'default': {
'allowedContent': True,
},
}
在文章模型中我有:
description = RichTextField()
我遇到的问题是,当我尝试在 CKEditor 源中插入 Google Adsense 广告单元代码并像这样保存时:
保存后,CKEditor 会从 Adsense 广告代码中删除 ins 标签,如下所示:
如何防止 CKEditor 从 Adsense 代码中剥离标签?
我尝试通过将两行添加到 CKEditor 的 config.js 文件来实现此处建议的解决方案,但这没有任何效果: 如何在 django-ckeditor 中推送受保护的源?
/**
* @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see https://ckeditor.com/legal/ckeditor-oss-license
*/
CKEDITOR.editorConfig = function( config ) {
// Define changes to default configuration here. For example:
// config.language = 'fr';
// config.uiColor = '#AADC6E';
config.protectedSource.push( /<ins[\s|\S]+?<\/ins>/g );
config.protectedSource.push( /<ins class=\"adsbygoogle\"\>.*?<\/ins\>/g );
};
这导致了另一个问题:如何确保 CKEditor 的 config.js 文件正在被应用,因为它目前似乎尚未被应用?
确保您的 CKEDITOR_BASEPATH 指向您本地的 CKEditor 静态文件而不是您的产品:
CKEDITOR_BASEPATH = '/static/ckeditor/ckeditor/'
我还切换回 CKEditor 4,因为即使更改为正确的 CKEDITOR_BASEPATH 后 5 也无法工作。