问题
I'm trying to use 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. How to also configure Quill to use the mentioned restricted tag set? No other tags can be allowed and must be automatically removed if present.
回答1:
Define formats
in the parameters of the constructor, there you can define which formats you want to support.
var quill = new Quill('#editor-container', {
formats: ['bold', 'italic', 'code', 'code-block', 'link'],
...
});
回答2:
Quill works with Delta and formats, not directly with HTML and tags. You can set the formats config option to limit the allowed formats.
回答3:
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.
来源:https://stackoverflow.com/questions/52223982/quill-javascript-rich-text-editor-restrict-tags