【问题标题】:Remove colors when pasting on ngx quill field在 ngx quill 字段上粘贴时删除颜色
【发布时间】:2021-08-16 18:53:44
【问题描述】:

我正在使用ngx-quill 编辑器,到目前为止它具有我需要的所有功能。但是,我没有看到有关如何删除来自剪贴板的文本的背景颜色和字体颜色的任何选项。

我想保留除颜色之外的所有其他格式。这可能吗?

【问题讨论】:

    标签: angular quill ngx-quill


    【解决方案1】:

    对于和我有同样问题的人,我设法找到了解决方法。

    在我看来:

    <quill-editor (onEditorCreated)='editorInit($event)'></quill-editor>
    

    在我的控制器上

    editorInit(quill: any){
        quill.clipboard.addMatcher(Node.ELEMENT_NODE, function(node, delta){
          delta.forEach(e => {
            if(e.attributes){
              e.attributes.color = '';
              e.attributes.background = '';
            }
          });
          return delta;
        });
      }
    

    【讨论】:

    • 很高兴您不仅找到了问题的解决方案,还在这里与社区分享了它。谢谢你。我应该只添加一个小细节:下次您提出问题时,请尝试更清楚并提供有关您的问题的更多详细信息。作为提示,请阅读this page。希望再次在这里见到你,好吗?待会见。
    【解决方案2】:
    • 如果您不想使用@manoyanx 的答案中提到的事件侦听器来删除颜色和背景,您可以使用

        const myQuillEditorFormats = ["background", "bold", "color", "font", "code", "italic", "link", "size", "strike", "script", "underline", "blockquote", "header", "indent", "list", "align", "direction", "code-block", "formula", "image", "video"];
      
    • 在上面的 myQuillEditorFormats 数组中,我添加了所有默认的羽毛笔编辑器选项。您可以专门删除您不想要的选项。

    • 然后在你的 NgModule 的导入中

        QuillModule.forRoot({ formats: quillEditorFormats })
      

    来源:https://quilljs.com/docs/formats/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多