代码之家  ›  专栏  ›  技术社区  ›  alexanoid

Quill JavaScript富文本编辑器限制标记

  •  0
  • alexanoid  · 技术社区  · 7 年前

    我正在尝试使用quilljavascript富文本编辑器。我需要将其配置为仅使用预定义的标记集:

    b, i, pre, a, br + Emoji
    

    现在,我已按以下方式对其进行了配置:

    var Block = Quill.import('blots/block');
    Block.tagName = 'PRE';
    Quill.register(Block, true);
    
    var quill = new Quill('#editor-container', {
      modules: {
        toolbar: true
      },
      theme: 'snow'
    });
    

    如你所见,我已经把包装改成 PRE 标签。如何配置Quill来使用所提到的限制标记集?不允许使用其他标签,如果存在,则必须自动删除。

    2 回复  |  直到 7 年前
        1
  •  1
  •   martinstoeckli    7 年前

    定义 formats 在构造函数的参数中,可以定义要支持的格式。

    var quill = new Quill('#editor-container', {
      formats: ['bold', 'italic', 'code', 'code-block', 'link'],
      ...
    });
    
        2
  •  1
  •   Ben Browitt    7 年前

    Delta formats 你可以设置 formats config选项来限制允许的格式。

        3
  •  1
  •   Rahul Dudhane    5 年前

    以下是所有格式的列表:

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

    您可以使用它来阻止某些格式。