{"id":13509624,"url":"https://github.com/nozer/quill-delta-to-html","last_synced_at":"2026-01-11T17:58:32.811Z","repository":{"id":19710823,"uuid":"87703209","full_name":"nozer/quill-delta-to-html","owner":"nozer","description":"Converts Quill's delta ops to HTML","archived":false,"fork":false,"pushed_at":"2024-05-24T17:39:54.000Z","size":809,"stargazers_count":407,"open_issues_count":34,"forks_count":95,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-10-30T17:11:43.550Z","etag":null,"topics":["delta","html","quilljs"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nozer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-09T11:21:30.000Z","updated_at":"2024-10-28T19:29:44.000Z","dependencies_parsed_at":"2024-01-13T20:45:46.784Z","dependency_job_id":"8c677d56-940b-42b3-9109-c4f42edef734","html_url":"https://github.com/nozer/quill-delta-to-html","commit_stats":{"total_commits":154,"total_committers":17,"mean_commits":9.058823529411764,"dds":0.5974025974025974,"last_synced_commit":"a75bc6b161331c95423936ab4879cc9bc3b46b3a"},"previous_names":[],"tags_count":51,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nozer%2Fquill-delta-to-html","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nozer%2Fquill-delta-to-html/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nozer%2Fquill-delta-to-html/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nozer%2Fquill-delta-to-html/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nozer","download_url":"https://codeload.github.com/nozer/quill-delta-to-html/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222308100,"owners_count":16964309,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["delta","html","quilljs"],"created_at":"2024-08-01T02:01:10.534Z","updated_at":"2026-01-11T17:58:32.803Z","avatar_url":"https://github.com/nozer.png","language":"TypeScript","funding_links":[],"categories":["TypeScript","Uncategorized"],"sub_categories":["Uncategorized"],"readme":"[![Build Status](https://travis-ci.org/nozer/quill-delta-to-html.svg?branch=master)](https://travis-ci.org/nozer/quill-delta-to-html) \n[![Coverage Status](https://coveralls.io/repos/github/nozer/quill-delta-to-html/badge.svg?branch=master)](https://coveralls.io/github/nozer/quill-delta-to-html?branch=master)\n\n\n# Quill Delta to HTML Converter #\nConverts [Quill's](https://quilljs.com) [Delta](https://quilljs.com/docs/delta/) format to HTML (insert ops only) with properly nested lists.\n\nYou can try a live demo of the conversion by opening the `demo-browser.html` file after cloning the repo.\n\n## Breaking change: `import/require` has changed as of `v0.10.0`. See Usage below ##\n\n\n\n## Quickstart ## \n\nInstallation\n```\nnpm install quill-delta-to-html\n```\n\nUsage\n```javascript\nvar QuillDeltaToHtmlConverter = require('quill-delta-to-html').QuillDeltaToHtmlConverter;\n\n// TypeScript / ES6:\n// import { QuillDeltaToHtmlConverter } from 'quill-delta-to-html'; \n\nvar deltaOps =  [\n    {insert: \"Hello\\n\"},\n    {insert: \"This is colorful\", attributes: {color: '#f00'}}\n];\n\nvar cfg = {};\n\nvar converter = new QuillDeltaToHtmlConverter(deltaOps, cfg);\n\nvar html = converter.convert(); \n```\n\n## Configuration ## \n\n`QuillDeltaToHtmlConverter` accepts a few configuration options as shown below:\n\n|Option | Type | Default | Description \n|---|---|---|---|\n|`paragraphTag`| string |  'p' | Custom tag to wrap inline html elements|\n|`encodeHtml`| boolean | true | If true, `\u003c, \u003e, /, ', \", \u0026` characters in content will be encoded.|\n|`classPrefix`| string | 'ql' | A css class name to prefix class generating styles such as `size`, `font`, etc. |\n|`inlineStyles`| boolean or object | false | If true or an object, use inline styles instead of classes. See Rendering Inline Styles section below for using an object |\n|`multiLineBlockquote`| boolean | true | Instead of rendering multiple `blockquote` elements for quotes that are consecutive and have same styles(`align`, `indent`, and `direction`), it renders them into only one|\n|`multiLineHeader`| boolean | true | Same deal as `multiLineBlockquote` for headers|\n|`multiLineCodeblock`| boolean | true | Same deal as `multiLineBlockquote` for code-blocks|\n|`multiLineParagraph`| boolean | true | Set to false to generate a new paragraph tag after each enter press (new line)|\n|`linkRel`| string | none generated | Specifies a value to put on the `rel` attr on all links. This can be overridden by an individual link op by specifying the `rel` attribute in the respective op's attributes|\n|`linkTarget`| string | '_blank' | Specifies target for all links; use `''` (empty string) to not generate `target` attribute. This can be overridden by an individual link op by specifiying the `target` with a value in the respective op's attributes.|\n|`allowBackgroundClasses`| boolean | false | If true, css classes will be added for background attr|\n|`urlSanitizer`| function `(url: string): string \\| undefined` | undefined | A function that is called once per url in the ops (image, video, link) for you to do custom sanitization. If your function returns a string, it is assumed that you sanitized the url and no further sanitization will be done by the library; when anything other than a string is returned (e.g. `undefined`), it is assumed that no sanitization has been done and the library's own function will be used to clean up the url|\n|`customTag`| function `(format: string, op: DeltaInsertOp): string \\| undefined` | undefined | Callback allows to provide custom html tag for some format|\n|`customTagAttributes`| function `(op: DeltaInsertOp): { [key: string]: string } \\| undefined` | undefined | Allows to provide custom html tag attributes|\n|`customCssClasses`| function `(op: DeltaInsertOp): string \\| string[] \\| undefined` | undefined | Allows to provide custom css classes|\n|`customCssStyles`| function `(op: DeltaInsertOp): string \\| string[] \\| undefined` | undefined | Allows to provide custom css styles|\n\n\n## Rendering Quill Formats ##\n\nYou can customize the rendering of Quill formats by registering to the render events before calling the `convert()` method. \n\nThere are `beforeRender` and `afterRender` events and they are called multiple times before and after rendering each group. A group is one of:\n\n- continuous sets of inline elements\n- a video element\n- list elements\n- block elements (header, code-block, blockquote, align, indent, and direction)\n\n`beforeRender` event is called with raw operation objects for you to generate and return your own html. If you return a `falsy` value, system will return its own generated html. \n\n`afterRender` event is called with generated html for you to inspect, maybe make some changes and return your modified or original html.\n\n```javascript\n\nconverter.beforeRender(function(groupType, data){\n    // ... generate your own html \n    // return your html\n});\nconverter.afterRender(function(groupType, htmlString){\n    // modify if you wish\n    // return the html\n});\n\nhtml = converter.convert();\n\n```\n\nFollowing shows the parameter formats for `beforeRender` event: \n\n\n\n|groupType|data|\n|---|---|\n|`video`|{op: `op object`}|\n|`block`|{op: `op object`: ops: Array\u003c`op object`\u003e}|\n|`list`| {items: Array\u003c{item: `block`, innerList: `list` or `null` }\u003e }|\n|`inline-group`|{ops: Array\u003c`op object`\u003e}|\n\n`op object` will have the following format: \n\n```javascript\n{\n    insert: {\n        type: '' // one of 'text' | 'image' | 'video' | 'formula',\n        value: '' // some string value  \n    }, \n    attributes: {\n        // ... quill delta attributes \n    }\n}\n```\n\n## Rendering Inline Styles ##\n\nIf you are rendering to HTML that you intend to include in an email, using classes and a style sheet are not recommended, as [not all browsers support style sheets](https://www.campaignmonitor.com/css/style-element/style-in-head/).  quill-delta-to-html supports rendering inline styles instead.  The easiest way to enable this is to pass the option `inlineStyles: true`.\n\nYou can customize styles by passing an object to `inlineStyles` instead:\n\n```javascript\ninlineStyles: {\n   font: {\n      'serif': 'font-family: Georgia, Times New Roman, serif',\n      'monospace': 'font-family: Monaco, Courier New, monospace'\n   },\n   size: {\n      'small': 'font-size: 0.75em',\n      'large': 'font-size: 1.5em',\n      'huge': 'font-size: 2.5em'\n   },\n   indent: (value, op) =\u003e {\n      var indentSize = parseInt(value, 10) * 3;\n      var side = op.attributes['direction'] === 'rtl' ? 'right' : 'left';\n      return 'padding-' + side + ':' + indentSize + 'em';\n   },\n   direction: (value, op) =\u003e {\n      if (value === 'rtl') {\n         return 'direction:rtl' + ( op.attributes['align'] ? '' : '; text-align: inherit' );\n      } else {\n         return '';\n      }\n   }\n};\n```\n\nKeys to this object are the names of attributes from Quill.  The values are either a simple lookup table (like in the 'font' example above) used to map values to styles, or a `fn(value, op)` which returns a style string.\n\n## Rendering Custom Blot Formats ##\n\nYou need to tell system how to render your custom blot by registering a renderer callback function to `renderCustomWith` method before calling the `convert()` method. \n\nIf you would like your custom blot to be rendered as a block (not inside another block or grouped as part of inlines), then add `renderAsBlock: true` to its attributes. \n\nExample:\n```javascript \nlet ops = [\n    {insert: {'my-blot': {id: 2, text: 'xyz'}}, attributes: {renderAsBlock: true|false}}\n];\n\nlet converter = new QuillDeltaToHtmlConverter(ops);\n\n// customOp is your custom blot op\n// contextOp is the block op that wraps this op, if any. \n// If, for example, your custom blot is located inside a list item,\n// then contextOp would provide that op. \nconverter.renderCustomWith(function(customOp, contextOp){\n    if (customOp.insert.type === 'my-blot') {\n        let val = customOp.insert.value;\n        return `\u003cspan id=\"${val.id}\"\u003e${val.text}\u003c/span\u003e`;\n    } else {\n        return 'Unmanaged custom blot!';\n    }\n});\n\nhtml = converter.convert();\n```\n`customOp object` will have the following format: \n\n```javascript\n{\n    insert: {\n        type: string //whatever you specified as key for insert, in above example: 'my-blot'\n        value: any // value for the custom blot  \n    }, \n    attributes: {\n        // ... any attributes custom blot may have\n    }\n}\n```\n\n## Advanced Custom Rendering Using Grouped Ops ##\n\nIf you want to do the full rendering yourself, you can do so \nby getting the processed \u0026 grouped ops.\n\n```javascript\nlet groupedOps = converter.getGroupedOps();\n```\nEach element in groupedOps array will be an instance of the \nfollowing types: \n\n|type|properties|\n|---|---|\n|`InlineGroup`|ops: Array\u003c`op object`\u003e|\n|`VideoItem`|op: `op object`|\n|`BlockGroup`|op: `op object`, ops: Array\u003c`op object`\u003e|\n|`ListGroup`|items: Array\u003c`ListItem`\u003e|\n||ListItem: {item:`BlockGroup`, innerList:`ListGroup`}|\n|`BlotBlock`|op: `op object`|\n\n`BlotBlock` represents custom blots with `renderAsBlock:true` property pair in its attributes\n\nSee above for `op object` format. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnozer%2Fquill-delta-to-html","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnozer%2Fquill-delta-to-html","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnozer%2Fquill-delta-to-html/lists"}