Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove colors when pasting on ngx quill field

I am using the ngx-quill editor and so far it has all the features that I need. However, I don't see any options on how to remove the background colors and font colors of the text coming from the clipboard.

I want to retain all the other formatting except the colors. Is this possible?

like image 989
manoyanx Avatar asked Oct 17 '25 21:10

manoyanx


2 Answers

For anyone having the same issue with me, I managed to find a workaround for this.

On my view :

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

On my Controller

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;
    });
  }
like image 200
manoyanx Avatar answered Oct 22 '25 06:10

manoyanx


  • If you don't want to remove color and background using event listeners as mentioned in @manoyanx's answer, you can use

      const myQuillEditorFormats = ["background", "bold", "color", "font", "code", "italic", "link", "size", "strike", "script", "underline", "blockquote", "header", "indent", "list", "align", "direction", "code-block", "formula", "image", "video"];
    
  • In the above myQuillEditorFormats array, I have added all default quill editor options. You can specifically remove the options which you don't want.

  • Then in your NgModule's imports

      QuillModule.forRoot({ formats: quillEditorFormats })
    

Source: https://quilljs.com/docs/formats/

like image 29
Sivaraman Avatar answered Oct 22 '25 05:10

Sivaraman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!