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

QuillDeltaToHtmlConverter returns blank #93

Open
Doetheman opened this issue Sep 14, 2020 · 6 comments
Open

QuillDeltaToHtmlConverter returns blank #93

Doetheman opened this issue Sep 14, 2020 · 6 comments

Comments

@Doetheman
Copy link

I am currently fetching delta data from my database and using convert() to convert the delta value to HTML. For some reason, the value returns a blank string but before convert() the object was assigned delta. What could be the issue?

EXAMPLE:
const QuillDeltaToHtmlConverter = require('quill-delta-to-html').QuillDeltaToHtmlConverter;

jobs.forEach(job => {
const cfg = {};
const cfg2 = {};
const converterDesc = new QuillDeltaToHtmlConverter(job.info.description.toString());
const converterReq = new QuillDeltaToHtmlConverter(job.info.requirements.toString());
job.info.description = converterDesc.convert();
job.info.requirements = converterReq.convert();
});

converterDesc contains this before I call the convert() function:

rawDeltaOps:'{"ops":[{"attributes":{"bold":true},"insert":"Looking for Independent and Growth Mindset Designer"},{"insert":"\nLooking for UI/UX designs to assist our team to support black businesses in becoming digital resilient. Our team consult with startups and small business and offer services to design & develop their digital solution.\n\n"}]}'

I tried without toString()

@lushiyun
Copy link

I'm having the same issue. Converter rawDeltaOps shows result similar to yours but the convert() function returns blank.

import { QuillDeltaToHtmlConverter } from 'quill-delta-to-html'
const cfg = {}
const converter = new QuillDeltaToHtmlConverter(
    JSON.parse(message.content),
    cfg
)
const html = converter.convert()

@Rikhart
Copy link

Rikhart commented Nov 11, 2020

I have the same issue, any news about this bug ?

@lushiyun
Copy link

lushiyun commented Nov 11, 2020

Are you using React? If so, I found a workaround:

const deltaOps = JSON.parse(message.content)

const quillHtml = () => {
    const temp = new Quill(document.createElement('div'))
    temp.setContents(deltaOps)
    return { __html: temp.root.innerHTML }
  }

return <div dangerouslySetInnerHTML={quillHtml()}></div>

@martinschilliger
Copy link

martinschilliger commented Nov 16, 2020

I often stumbled over this… don't supply the delta to the converter, supply delta.ops. So the example of @Doetheman would be:

const QuillDeltaToHtmlConverter = require('quill-delta-to-html').QuillDeltaToHtmlConverter;

jobs.forEach(job => {
  const cfg = {};
  const cfg2 = {};
  const converterDesc = new QuillDeltaToHtmlConverter(job.info.description.ops);
  const converterReq = new QuillDeltaToHtmlConverter(job.info.requirements.ops);
  job.info.description = converterDesc.convert();
  job.info.requirements = converterReq.convert();
});

I don't know why you are using toString() here, you have to pass the JavaScript Object to the converter.

@yklim
Copy link

yklim commented Dec 3, 2020

typescript + react . Works fine!

import { QuillDeltaToHtmlConverter } from 'quill-delta-to-html';

const cfg = {};

function deltaToHtml(delta: string) {
  const _delta = JSON.parse(delta);
  const converter = new QuillDeltaToHtmlConverter(_delta.ops, cfg);
  const html = converter.convert();
  return html;

...
<div dangerouslySetInnerHTML={{ __html: quillToHtml(data) }} />

@hhvdblom
Copy link

hhvdblom commented Feb 23, 2023

I often stumbled over this… don't supply the delta to the converter, supply delta.ops. So the example of @Doetheman would be:

const QuillDeltaToHtmlConverter = require('quill-delta-to-html').QuillDeltaToHtmlConverter;

jobs.forEach(job => {
  const cfg = {};
  const cfg2 = {};
  const converterDesc = new QuillDeltaToHtmlConverter(job.info.description.ops);
  const converterReq = new QuillDeltaToHtmlConverter(job.info.requirements.ops);
  job.info.description = converterDesc.convert();
  job.info.requirements = converterReq.convert();
});

I don't know why you are using toString() here, you have to pass the JavaScript Object to the converter.

What I did forget was to first make a JSON object of the String I got from the database with JSON.parse(delta). After that I put the Delta with ops in it and it works fine :-) Thanks for the community to make this possible :-)

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

6 participants