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

use quillclasses like ql-align-right instead of inline styles #43

Open
daslicht opened this issue May 21, 2018 · 6 comments
Open

use quillclasses like ql-align-right instead of inline styles #43

daslicht opened this issue May 21, 2018 · 6 comments

Comments

@daslicht
Copy link

Hi,
when we set the alignment of an image inline styles get added.
There however are removed when you use them to initialize a quill:

slab/quill#2126

Any idea ?

@koan00
Copy link

koan00 commented May 21, 2018

The inline styles need to be registered to Quill, or else they are stripped.

There maybe better ways to do it, but I resolved it like this: koan00@95ba869

@daslicht
Copy link
Author

any downside ? or is it ready to be mergred ?

@koan00
Copy link

koan00 commented May 22, 2018

Well the downside would be if overwrites the default image implementation of quill. If something else also needs to override the default implementation, there would be a conflict. The solution was found here: #10

I believe the code itself does not even have to be part of the resize module, and could be implemented separately. I just integrated it for ease of use for my narrow usage scope.

@arimus
Copy link

arimus commented Oct 3, 2019

Confirmed that the solution @koan00 mentioned works. FYI, I was able to use this snippet right after my Quill import to get things working (included below from the commit referenced above). My recommendation would be to include this override code and provide a flag to disable it (and document that). This way we can get this working properly out of the box, but allow folks to disable it if needed (or the other way around).

import Quill from 'quill';

// BEGIN allow image alignment styles
const ImageFormatAttributesList = [
  'alt',
  'height',
  'width',
  'style'
];

const BaseImageFormat = Quill.import('formats/image');
class ImageFormat extends BaseImageFormat {
  static formats(domNode) {
    return ImageFormatAttributesList.reduce(function(formats, attribute) {
      if (domNode.hasAttribute(attribute)) {
        formats[attribute] = domNode.getAttribute(attribute);
      }
      return formats;
    }, {});
  }
  format(name, value) {
    if (ImageFormatAttributesList.indexOf(name) > -1) {
      if (value) {
        this.domNode.setAttribute(name, value);
      } else {
        this.domNode.removeAttribute(name);
      }
    } else {
      super.format(name, value);
    }
  }
}

Quill.register(ImageFormat, true);
// END allow image alignment styles

@dextel2
Copy link

dextel2 commented Jun 20, 2022

@arimus Can you provide TS version, I am facing difficulty in reduce

@arimus
Copy link

arimus commented Jun 20, 2022

@arimus Can you provide TS version, I am facing difficulty in reduce

I believe I was using 3.8.3 at the time. If you are stuck on a version without reduce, you could use a polyfill or work around with a filter and a manual dedupe loop.

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

4 participants