如何在基于Quill的编辑器中粘贴纯文本 [英] How to paste plain text in a Quill-based editor

查看:831
本文介绍了如何在基于Quill的编辑器中粘贴纯文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Quill( https://quilljs.com/ )使在网络中嵌入高质量文本编辑器变得简单页。在编辑器中粘贴html内容时,它会过滤粘贴的html,然后将其放入文本编辑器中。我的问题是:如何配置羽毛笔,使其仅在文本编辑器中粘贴纯文本?

Quill (https://quilljs.com/) makes it simple to embed a quality text editor in a web page. When pasting html content in the editor, it filters the pasted html and then puts it into the text editor. My question is: How can I configure Quill so it pastes only plain text in the text editor? It would filter out all tags and leave the plain text only.

有关剪贴板模块的文档( http://quilljs.com/docs/modules/clipboard/ )表示,可以向剪贴板添加自定义匹配器,从而可以过滤粘贴的内容

The documentation about the Clipboard module (http://quilljs.com/docs/modules/clipboard/) says that it is possible to add custom Matchers to the Clipboard, that will kind of filter the pasted text.

我不知道如何编写只允许纯文本的匹配器。

I don't know how to write a matcher that only allows plain text. Any help and any examples are much appreciated - thanks!

推荐答案

经过反复试验,我找到了答案。以下匹配器将使编辑器仅粘贴纯文本:

After trial and error, I found the answer. The following matcher will cause the editor to paste plain text only:

quill.clipboard.addMatcher (Node.ELEMENT_NODE, function (node, delta) {
    var plaintext = $ (node).text ();
    return new Delta().insert (plaintext);
});

它使用jQuery。 :)

It uses jQuery. :)

这篇关于如何在基于Quill的编辑器中粘贴纯文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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