nehem
nehem

Reputation: 13642

Python: Convert Quill delta to HTML

My existing project is using quill.js, And a sample quill content(delta) will look something like this

{
  "ops": [
    {
      "attributes": {
        "underline": true,
        "bold": true
      },
      "insert": " dfsdfdsf "
    },
    {
      "insert": "\n"
    }
  ]
}

Are there any pure python ways to convert these content into HTML?. I need this as a part of report generation to PDF on the server side using WeasyPrint.

Note: Kindly do not attempt to answer if you haven't used Quill.js before, or at least know what it is.

Upvotes: 3

Views: 2887

Answers (1)

GlenPeterson
GlenPeterson

Reputation: 5216

If want to plain HTML in order to submit it to your server (for the entire edited document), you can just grab quill.root.innerHTML (which is the HTML inside the quill edit box) when your form is submitted (when the Submit button is pressed).

<form action="/SomeAction"
      method="POST"
      onsubmit="this['contents'].value = quill.root.innerHTML;"
      name="contentForm">
    <input type="hidden" name="id" value="239" />
    <input type="hidden" name="contents" value="" />
    <input type="submit" value="Submit">
</form>

Upvotes: 8

Related Questions