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

Inline styling lost after loading/pasting html #1580

Closed
drego opened this issue Jul 10, 2017 · 11 comments
Closed

Inline styling lost after loading/pasting html #1580

drego opened this issue Jul 10, 2017 · 11 comments

Comments

@drego
Copy link

drego commented Jul 10, 2017

I'm currently trying to use Quill to create an editor and be able to format an email in HTML.
In order to allow the styling of the email content I'm using only inline styling attributes instead of the quill classes.
However, when I try to load or paste the html content into the editor, some of the inline styles are ignored/removed. I noticed that some of the inline styles (like color, background-color,text-align) are kept but others are just removed (for instance some font families and text-indent).
Here is a verifiable example of this problem.

Steps for Reproduction

  1. Visit the example provided
  2. Verify that some inline fonts are applied by Quill and others are ignored.
  3. Verify that the indent specified with inline styling is ignored by Quill.

Expected behavior:
The fonts and indent specified by inline styling should be recognized and kept by Quill.

Actual behavior:
Some fonts are kept and others are removed when loading Quill. Text indent specified by inline styling is also removed.

Platforms:
Google Chrome Version 58.0.3029.110 (64-bit)

Version:
1.2.6

@revmischa
Copy link

This is a high priority issue for us, we need the ability to initialize the editor with some pre-existing HTML with inline styling.

@sendlane-ray
Copy link

Is there a workaround for this?

@revmischa
Copy link

yeah switch to a different editor lmao

@sendlane-ray
Copy link

Downgrade to version 1.0.3. (bug started with version 1.0.4)
or delete the whitelist.

This bug only happens when the font family has quotes.

import Quill from 'quill';

let Font = Quill.import('attributors/style/font');
delete Font.whitelist;

Quill.register(Font);

@jhchen
Copy link
Member

jhchen commented Jan 22, 2018

This is fixed with the fix from #1873 fa99fa0 for font family. The expected case for text indent is replace with a tab character, which it already does.

@jhchen jhchen closed this as completed Jan 22, 2018
@dynothunder
Copy link

The expected case for text indent is replace with a tab character, which it already does. can't understand where you told about tab character

@pdkovacs
Copy link

pdkovacs commented May 23, 2019

I am still having this issue with version 1.3.6 with code based on this example: https://stackoverflow.com/questions/43728080/how-to-add-font-types-on-quill-js-with-toolbar-options (And the issue is -- still -- with font families having white space(s) included in their names.)

The key difference compared with the test code here is how the font "module" is imported:
formats/font vs attributors/style/font .
Is one of them incorrect? Are they both correct, just serving different purpose?

@MwumLi
Copy link

MwumLi commented Nov 29, 2019

how to solve this?

@bogoroh
Copy link

bogoroh commented Dec 30, 2020

@drego, Did you fix this? Still having the issue

@komendantaa
Copy link

komendantaa commented Nov 7, 2023

I've found a workaround.

"quill": "^1.3.7"

 editorCreated(quill: Quill) {
    quill.clipboard.addMatcher(Node.ELEMENT_NODE, function (node, delta) {
      const font = node.className.match(/(?<=ql-font-)(\w*-?)*/)?.[0];
      if (font) {
        return new Delta().insert(node.textContent, {
          ...(delta?.ops?.[0].attributes ?? {}),
          font: font,
        })
      }
      return delta
    })
    this.content = this._content;
  }

Worked for me.

@ViktorDimitrievski
Copy link

I am still having this issue with version 1.3.6 with code based on this example: https://stackoverflow.com/questions/43728080/how-to-add-font-types-on-quill-js-with-toolbar-options (And the issue is -- still -- with font families having white space(s) included in their names.)

The key difference compared with the test code here is how the font "module" is imported: formats/font vs attributors/style/font . Is one of them incorrect? Are they both correct, just serving different purpose?

Wow.... When you use

customOptions: [
   		{
   			        import: 'formats/font',
   				whitelist: [
   					'arial',
   					'arialBlack',
   					'helvetica',
   					'monospace',
   					'georgia',
   					'book',
   					'comic',
   					'courier',
   					'tahoma',
   					'terminal',
   					'monaco',
   					'times',
   					'trebuchet',
   					'verdana',
   				],
   			},
   

end result would be <p><span class="ql-font-comic">Hello ComincSans</span></p>

But when u change only import to import: 'attributors/style/font',
result would be <p><span style="font-family: comic;">Hello ComincSans</span></p>

After hour of search I have found out this ...which in documentation can not be found. Nice! Thank you @pdkovacs

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

No branches or pull requests

10 participants