将 CKEditor 高级内容过滤器应用于字符串 [英] Apply CKEditor Advanced Content Filter to a string

查看:21
本文介绍了将 CKEditor 高级内容过滤器应用于字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将 CKEditor 的高级内容过滤器应用于字符串?

How can I apply CKEditor's Advanced Content Filter to a string?

我正在尝试使用 editor.on('paste', ...) 截取粘贴的内容,获取其 ACF 过滤值,然后将我自己的转换应用于过滤值.过了这一步,再跑一遍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 中引入.(编辑:CKEditor 在 4.5 中提供了此功能 – 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:

  1. 使用 CKEDITOR.htmlParser 解析它.fragment.fromHtml().
  2. 调用filter.applyTo 在上一步创建的文档片段上.您可以使用标准的 editor.filter 或使用不同的设置创建您自己的实例.
  3. 将文档片段序列化回 HTML 字符串.

例如:

    // 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屋!

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