如何配置CKEditor,使其保留数据属性而不是删除它们? [英] How to configure CKEditor so it keeps data attributes instead of removing them?

查看:92
本文介绍了如何配置CKEditor,使其保留数据属性而不是删除它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用CKeditor编辑丰富的HTML页面,但某些JavaScript功能依赖于触发它们的< a> 标记的特殊属性。

I use CKeditor for editing rich HTML pages, but some javascript functionality relies on special attributes of the <a> tags that triggers them.

这种情况很少见,只有5000多个记录的数据库中的少数记录需要触发此功能,而这个特殊的js模块需要特殊的属性作为参数化方式:

Those are rare cases, just a few records on a database of 5000+ records need to trigger this functionality, and this particular js module needs special attributes as a way of parametrization:

<a href="#" data-from="ROM" data-to="NYC" data-promo="8373794">Buy your tickets</a>

CKeditor允许我添加这些属性(通过编辑条目的源代码),但是当客户端编辑页面,编辑器将其删除并破坏该功能。

CKeditor allows me to add those attributes (by editing the source code of the entry), but when the client edits the page the editor removes them and breaks that functionality.

指示我的客户不要编辑此特定记录似乎并不专业。更改为其他WYSIWYG编辑器也许可以,但是我认为这是最后的选择。

Instructing my client to not edit this particular record seems unprofessional. Changing to another WYSIWYG editor may work, but I see that as the last resort.

CKEditor必须对此有解决方案!

CKEditor has to have a solution to that!

推荐答案

我找到了它:

特殊配置选项:

            extraAllowedContent: '*[*]{*}(*)'

起到了作用。

所以我使用的构造函数是:

So the constructor I use is:

    $('.wysiwyg').ckeditor({
            toolbar : 'Basic',
            extraAllowedContent: '*[*]{*}(*)'
    });

请注意,这是允许的 EXTRA内容选项,因此不会覆盖默认值。

Note that it's the "EXTRA" allowed content option, so it does not overwrite the default.

更新:事实证明,我的特殊属性有一些&在其中,CKEditor用HTML实体& 替换了它们。我添加了这两个选项:

Update: It turns out that my special attribute had some & in it, and CKEditor was replacing them with the HTML entity &amp;. I added these two options:

            entities: false,
            basicEntities: false,

,但它们阻止了这种情况仅发生在文本节点中,而不是在属性内部。然后我找到了这个选项:

but they prevented that from happening in text nodes only, not inside attributes. Then I found this option:

            forceSimpleAmpersand: true

,它奏效了。暂时还可以,但如果最终我不得不将& 用作任何值的一部分-实体,而不仅仅是& (通常在内容共享链接中是必需的)-编辑器将其破坏,将其更改为普通&。

and it worked. It'll be okay for now, but if eventually I have to put &amp; as part of any value --the entity, not just the & (this is usually required in content sharing links)-- the editor will break them, changing them to plain &.

这篇关于如何配置CKEditor,使其保留数据属性而不是删除它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆