如何在 QuillJS 中使用格式白名单? [英] How to use format whitelist in QuillJS?

查看:47
本文介绍了如何在 QuillJS 中使用格式白名单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了 Quill 文档、GitHub 主题以及 Stack Overflow 和我的此处一直无法找到使用 format 属性的简单示例.我想限制我的用户,以便他们只能使用粗体、斜体、下划线和超链接文本.

I have looked around the Quill documentation, GitHub topics, and here in Stack Overflow and I have been unable to find a simple example of using the format attribute. I would like to limit my users so that they can only bold, italicize, underline, and hyperlink text.

据我所知,这可以通过格式白名单来实现,但我只能找到有关自定义字体或其他更复杂属性的示例.

From what I understand, this can be achieved with a format whitelist, but I have only been able to find examples regarding custom fonts or other more complex properties.

感谢您的宝贵时间!

推荐答案

我进行了更多挖掘并找到了答案.下面创建了一个仅允许粗体、斜体、下划线和链接的 Quill 编辑器.允许的格式列表只是一个数组,编辑器中将不允许所有省略格式,因此它们不会在用户粘贴文本时显示.

I did some more digging around and found the answer. The following creates a Quill editor that allows only bold, italics, underline, and links. The list of allowed formats is just an array, and all omitted formats will not be allowed in the editor, so they won't show up if a user pastes text.

var toolbarOptions = [['bold', 'italic', 'underline'],['link'],['clean']];
var formatWhitelist = ['bold','italic','link'];

var quill = new Quill('#notification-message', {
    scrollingContainer: 'true',
    theme: 'snow',
    formats: formatWhitelist,
    modules: {
        toolbar: toolbarOptions
    }
});

这篇关于如何在 QuillJS 中使用格式白名单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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