slab / quill

Quill is a modern WYSIWYG editor built for compatibility and extensibility
https://quilljs.com
BSD 3-Clause "New" or "Revised" License
42.3k stars 3.31k forks source link

Paste HMTL removing inline style and HTML tags #4262

Open Alef-Martins opened 2 weeks ago

Alef-Martins commented 2 weeks ago

Hello!

I'm using Quill to render HTML code. There is a modal with an input where the user can paste some HTML code, and it sends the content to Quill. However, when the content is rendered by the component, the inline styles and some tags are removed. Is there a configuration to prevent those things from being removed?

`<div class="editor" [formGroup]="form">
  <quill-editor placeholder="" (onEditorCreated)="getEditorInstance($event)" #editorComponent theme="snow" format="html" formControlName="contentTinyHtml" imageResize="true" [modules]="modules" [sanitize]="true">
  </quill-editor>
</div>

<app-quill-editor-html-modal [quillContent]="form.get('contentTinyHtml')?.value" #quillModal (sendHtmlToQuillEditor)="hydrateContentInQuillEditor($event)"></app-quill-editor-html-modal>`
`ngOnInit(): void {

    const fontSizeArr = ['6px', '8px', '9px','10px', '11px', '12px', '13px', '14px', '16px', '18px', '24px', '30px', '36px', '48px'];
    const Size = this.Quill.import('attributors/style/size');
    Size.whitelist = fontSizeArr;
    this.Quill.register(Size, true);

    this.buildModule(Size);
  }

buildModule(size) {
    this.modules = {
      blotFormatter: {
        overlay: {
          style: {
            width: '100px',
            height: '100px',
          }
        }
      },
      'toolbar': {
        container: [
          ['bold', 'italic', 'underline', 'strike'],        // toggled buttons
          ['blockquote', 'code-block'],
          [{ 'header': 1 }, { 'header': 2 }],               // custom button values
          [{ 'list': 'ordered' }, { 'list': 'bullet' }],
          [{ 'script': 'sub' }, { 'script': 'super' }],      // superscript/subscript
          [{ 'indent': '-1' }, { 'indent': '+1' }],          // outdent/indent
          [{ 'direction': 'rtl' }],                         // text direction
          [{ 'color': [] }, { 'background': [] }],          // dropdown with defaults from theme
          [{ 'size': size.whitelist }],
          [{ 'font': [] }],
          [{ 'align': [] }],
          ['clean'],                                         // remove formatting button
          ['link', 'image'],                         // link and image, video
        ],
      },
      'clipboard': {
        allowed: {
            tags: ['a', 'b', 'strong', 'u', 's', 'i', 'p', 'br', 'ul', 'ol', 'li', 'span', 'center', 'table', 'td', 'tr', 'tbody'],
            attributes: ['href', 'rel', 'target', 'class', 'style']
        },
        keepSelection: true,
        substituteBlockElements: false,
        magicPasteLinks: true,
      }
    }
  }`

My ngx-quill version is 8.1.8