Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to remove unwanted formatting in pasted text #1687

Closed
zasunkx opened this issue Sep 6, 2017 · 4 comments
Closed

How to remove unwanted formatting in pasted text #1687

zasunkx opened this issue Sep 6, 2017 · 4 comments

Comments

@zasunkx
Copy link

zasunkx commented Sep 6, 2017

In my Quill editor, I am including only a limited selection of formatting options (bold, underlined, italic, link, blockquote, numerated list, bullet list). Now, I want to prevent users from bypassing these limitations by pasting formatted text (e.g. containing other text colors, monospace text, backgrounds, images) from a web page / document. How can I filter the text / content which is pasted into the quill editor in order to remove any other formatting options and elements apart from those stated above?

I am using Quill 1.3.1 with Angular.

@jonathanheron
Copy link

When you say you are including only a limited selection of formatting options, are you specifying a whitelist of formats in your editor options?

For example in my app I use these editor options:

{
  theme: 'snow',
  formats: [
    'bold',
    'header',
    'italic',
    'link',
    'list',
    'blockquote',
    'image',
    'indent'
  ],
  modules: {
    toolbar: [
      [{'header': 1}, {'header': 2}],
      ['bold', 'italic', 'link'],
      ['blockquote', {'list': 'ordered'}, {'list': 'bullet'}],
      ['image']
    ],
    clipboard: {
      matchVisual: false // https://quilljs.com/docs/modules/clipboard/#matchvisual
    }
  }
}

formats specifies a whitelist of formatting options/tags that can be used.

toolbar specifies which options appear on the toolbar.

matchVisual: false avoids Quill creating extra, empty lines if the source of the copy-paste includes a lot of padding before/after things like headings.

@zasunkx zasunkx closed this as completed Sep 8, 2017
@Mushood
Copy link

Mushood commented Apr 12, 2018

if you landed here if you're using vue2-editor,
you need to pass the following object to your vue2-editor component as such:

                optionsEditor: {
                    formats: [
                        'bold','underline','italic'
                    ],
                },

Component:

<vue-editor
                                      v-model="body"
                                      :editorOptions="optionsEditor"
                              ></vue-editor>

@krisnaw
Copy link

krisnaw commented Jul 26, 2018

@Mushood thanks for the tips

But it still will keep the format if it under the allowed tags.

For example we allow

tags. And under the

tags, there is a span tag with styles.

<p><span style="color:red">Text</span></p>

@koan00
Copy link

koan00 commented Dec 17, 2018

It looks like 'matchVisual: false' has been removed from the support docs. Is it still valid?
Edit: it's been removed from 2.0 documentation. Link to older version upgrade docs: https://github.com/quilljs/quill/blob/ee827ffb605ba491246f201d497ce0e7d9e193a0/docs/guides/upgrading-to-2-0.md#configuration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants