quill-delta-to-html icon indicating copy to clipboard operation
quill-delta-to-html copied to clipboard

img src attribute is set to [object Object]

Open bastienguillon opened this issue 4 years ago • 2 comments

I have found a weird behavior when converting images insert ops : the src attribute of the output img tag is always set to [object Object]

Here is a commit with a unit test which reproduces the issue: https://github.com/bastienguillon/quill-delta-to-html/commit/3ee6fdb05ac86344dc3c2895caed6327b0146b75

Input:

const delta = {
    ops: [
        {
            insert: {
                image: {
                    alt: null,
                    url: "https://i.imgur.com/XSoFJ8l.gif"
                }
            }
        }
    ]
};

const output = new QuillDeltaToHtmlConverter(delta.ops, { urlSanitizer: url => url }).convert();

Expected output

<p><img class="ql-image" src="https://i.imgur.com/XSoFJ8l.gif"/></p>

Actual output

<p><img class="ql-image" src="[object Object]"/></p>

bastienguillon avatar Dec 24 '20 09:12 bastienguillon

I wrote a dirty hack to temporarily fix the issue, but it is clearly not a viable solution

for (const op of delta.ops) {
	if (op?.insert?.image) {
		op.insert.image.toString = () => {
			return op.insert.image.url;
		};
	}
}

bastienguillon avatar Dec 24 '20 09:12 bastienguillon

in standard quill delta, image is string. It looks like you changed format

volser avatar Aug 23 '21 06:08 volser