简体   繁体   English

Quill JavaScript Rich Text Editor 限制标签

[英]Quill JavaScript Rich Text Editor restrict tags

I'm trying to use Quill JavaScript Rich Text Editor.我正在尝试使用 Quill JavaScript Rich Text Editor。 I need to configure it to use only a predefined tag set:我需要将其配置为仅使用预定义的标签集:

b, i, pre, a, br + Emoji

Right now I have configured it in the following way:现在我已经按以下方式配置了它:

var Block = Quill.import('blots/block');
Block.tagName = 'PRE';
Quill.register(Block, true);

var quill = new Quill('#editor-container', {
  modules: {
    toolbar: true
  },
  theme: 'snow'
});

As you may see I already have changed the wrapper to PRE tag.如您所见,我已经将包装器更改为PRE标记。 How to also configure Quill to use the mentioned restricted tag set?如何配置 Quill 以使用上述受限标签集? No other tags can be allowed and must be automatically removed if present.不允许有其他标签,如果存在,必须自动删除。

Quill works with Delta and formats , not directly with HTML and tags. Quill 使用Delta格式,而不是直接使用 HTML 和标签。 You can set the formats config option to limit the allowed formats.您可以设置格式配置选项来限制允许的格式。

Define formats in the parameters of the constructor, there you can define which formats you want to support.在构造函数的参数中定义formats ,在那里你可以定义你想要支持的格式。

var quill = new Quill('#editor-container', {
  formats: ['bold', 'italic', 'code', 'code-block', 'link'],
  ...
});

Here is the list of all formats:以下是所有格式的列表:

 formats = [
    // 'background',
    'bold',
    // 'color',
    // 'font',
    // 'code',
    'italic',
    // 'link',
    // 'size',
    // 'strike',
    // 'script',
    'underline',
    // 'blockquote',
    // 'header',
    // 'indent',
    'list',
    // 'align',
    // 'direction',
    // 'code-block',
    // 'formula'
    // 'image'
    // 'video'
  ];

You can use this to prevent some formats.您可以使用它来防止某些格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM