将CKEditor高级内容过滤器应用于字符串 [英] Apply CKEditor Advanced Content Filter to a string
问题描述
如何将CKEditor的高级内容过滤器应用到字符串?
How can I apply CKEditor's Advanced Content Filter to a string?
我试图使用editor.on('paste',...)拦截粘贴的内容。 ),获取其ACF筛选的值,然后将我自己的变换应用于筛选的值。
I'm trying to intercept pasted content using editor.on('paste', ...), get its ACF-filtered value, and then apply my own transformations to the filtered value. After this point, it's okay if it runs through the ACF again.
推荐答案
我最近报道了一张票,我认为你会有趣的是: http://dev.ckeditor.com/ticket/11621 。这个功能很有可能在CKEditor 4.5中引入。 (修改:此功能在4.5中已添加到CKEditor中 - CKEDITOR.config.pasteFilter
)。
I reported recently a ticket which I think you'll find interesting: http://dev.ckeditor.com/ticket/11621. There's a pretty high chance that this feature will be introduced in CKEditor 4.5. (Edit: This feature got to CKEditor in 4.5 – CKEDITOR.config.pasteFilter
).
至于您的问题 - 应用ACF您需要的HTML字符串:
As for your question - to apply ACF to an HTML string you need to:
- 使用
CKEDITOR.htmlParser.fragment.fromHtml()
。 - 致电
过滤器.applyTo
在上一步中创建的文档片段上。您可以使用标准editor.filter
或使用不同设置创建自己的实例。 - 将序列化文档片段回到HTML字符串。
- Parse it using
CKEDITOR.htmlParser.fragment.fromHtml()
. - Call
filter.applyTo
on document fragment created in previous step. You can either use the standardeditor.filter
or create your own instance with different settings. - Serialise document fragment back to HTML string.
例如:
// Create standalone filter passing 'p' and 'b' elements.
var filter = new CKEDITOR.filter( 'p b' ),
// Parse HTML string to pseudo DOM structure.
fragment = CKEDITOR.htmlParser.fragment.fromHtml( '<p><b>foo</b> <i>bar</i></p>' ),
writer = new CKEDITOR.htmlParser.basicWriter();
filter.applyTo( fragment );
fragment.writeHtml( writer );
writer.getHtml(); // -> '<p><b>foo</b> bar</p>'
这篇关于将CKEditor高级内容过滤器应用于字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!