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

Added capability to add blob url images #4208

Closed
wants to merge 1 commit into from
Closed

Conversation

didix16
Copy link

@didix16 didix16 commented May 14, 2024

This adds the capability to add images with blob urls. #4207

@luin
Copy link
Member

luin commented May 15, 2024

Thanks for the contribution! I think we can't support all protocols in the core as applications have different requirements. You should be able to extend the built-in Image format and override the sanitize method.

@didix16
Copy link
Author

didix16 commented May 15, 2024

Hi, thanks for your reply.
I don't understand this:

I think we can't support all protocols in the core as applications have different requirements

If you add more functionality to the core, aren't you improving the software? I mean, It becomes better in such way that It can handle more things and covers more needs.

That being said, how can I extend the Image module and override the sanitize function.

I think my contribution does that, right? I mean, I simply expanded the capabilities of the Image module.

Thanks.

@luin
Copy link
Member

luin commented May 16, 2024

Yeah you can extend Image and register your own image module with Quill.register().

If you add more functionality to the core, aren't you improving the software? I mean, It becomes better in such way that It can handle more things and covers more needs.

Supporting more things is not always better - applications may not want blob at all just like some of them don't like http.

@didix16
Copy link
Author

didix16 commented May 16, 2024

Mmmm I see.

So, to be able to extend Image to allow blob urls and register it to my Quill editor I must do something like this?

import Image from 'quill/formats/image'
import { sanitize } from 'quill/formats/link';
import Quill from 'quill';

class MyImage extends Image {
    static sanitize(url) {
        return sanitize(url, ['http', 'https', 'data', 'blob']) ? url : '//:0';
    }
}

Quill.register('formats/image', MyImage)

Is that correct?

EDIT:

I've tried it but I'm getting this error on insertImage:

Error: [Parchment] Cannot insert image into block

@luin
Copy link
Member

luin commented May 17, 2024

Yes, that's the way to register a custom image. Here's an example. Please provide a reproducible example if you encounter any issues.

@luin luin closed this May 17, 2024
@didix16
Copy link
Author

didix16 commented May 17, 2024

Thanks @luin, seems that with your example works. I don't know why, but if I try to import the image class directly don't work. After webpack done the compilation, MyImage is a function and imported Image is a class but using your example, by calling Quill.import('formats/image'), the Image is also a function and maybe there was a problem with the prototype chain when Quill checks if the custom format is an instanceof EmbledBlot...

Anyways, the problem is solved and working. Thanks

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

Successfully merging this pull request may close these issues.

None yet

2 participants