Installations
npm install quill-delta-to-html
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
15.4.0
NPM Version
7.0.15
Releases
Fixed inline code issue
Published on 28 Aug 2018
Added support for checked/unchecked lists
Published on 16 Aug 2018
Update tsconfig to be more strict and fixed ensuing errors
Published on 14 Aug 2018
Changed the way urls are verified
Published on 07 Aug 2018
Test fix
Published on 10 Jun 2018
Added type definitions
Published on 10 Jun 2018
Contributors
Languages
TypeScript (93.62%)
HTML (5.95%)
JavaScript (0.43%)
Developer
nozer
Download Statistics
Total Downloads
9,304,901
Last Day
7,865
Last Week
34,762
Last Month
169,571
Last Year
2,302,870
GitHub Statistics
413 Stars
183 Commits
95 Forks
6 Watching
7 Branches
15 Contributors
Bundle Size
41.10 kB
Minified
11.76 kB
Minified + Gzipped
Package Meta Information
Latest Version
0.12.1
Package Id
quill-delta-to-html@0.12.1
Unpacked Size
358.09 kB
Size
71.75 kB
File Count
89
NPM Version
7.0.15
Node Version
15.4.0
Total Downloads
Cumulative downloads
Total Downloads
9,304,901
Last day
-18.3%
7,865
Compared to previous day
Last week
-27.2%
34,762
Compared to previous week
Last month
4%
169,571
Compared to previous month
Last year
-23.6%
2,302,870
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Quill Delta to HTML Converter
Converts Quill's Delta format to HTML (insert ops only) with properly nested lists.
You can try a live demo of the conversion by opening the demo-browser.html
file after cloning the repo.
Breaking change: import/require
has changed as of v0.10.0
. See Usage below
Quickstart
Installation
npm install quill-delta-to-html
Usage
1var QuillDeltaToHtmlConverter = require('quill-delta-to-html').QuillDeltaToHtmlConverter; 2 3// TypeScript / ES6: 4// import { QuillDeltaToHtmlConverter } from 'quill-delta-to-html'; 5 6var deltaOps = [ 7 {insert: "Hello\n"}, 8 {insert: "This is colorful", attributes: {color: '#f00'}} 9]; 10 11var cfg = {}; 12 13var converter = new QuillDeltaToHtmlConverter(deltaOps, cfg); 14 15var html = converter.convert();
Configuration
QuillDeltaToHtmlConverter
accepts a few configuration options as shown below:
Option | Type | Default | Description |
---|---|---|---|
paragraphTag | string | 'p' | Custom tag to wrap inline html elements |
encodeHtml | boolean | true | If true, <, >, /, ', ", & characters in content will be encoded. |
classPrefix | string | 'ql' | A css class name to prefix class generating styles such as size , font , etc. |
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 |
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 |
multiLineHeader | boolean | true | Same deal as multiLineBlockquote for headers |
multiLineCodeblock | boolean | true | Same deal as multiLineBlockquote for code-blocks |
multiLineParagraph | boolean | true | Set to false to generate a new paragraph tag after each enter press (new line) |
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 |
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. |
allowBackgroundClasses | boolean | false | If true, css classes will be added for background attr |
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 |
customTag | function (format: string, op: DeltaInsertOp): string | undefined | undefined | Callback allows to provide custom html tag for some format |
customTagAttributes | function (op: DeltaInsertOp): { [key: string]: string } | undefined | undefined | Allows to provide custom html tag attributes |
customCssClasses | function (op: DeltaInsertOp): string | string[] | undefined | undefined | Allows to provide custom css classes |
customCssStyles | function (op: DeltaInsertOp): string | string[] | undefined | undefined | Allows to provide custom css styles |
Rendering Quill Formats
You can customize the rendering of Quill formats by registering to the render events before calling the convert()
method.
There are beforeRender
and afterRender
events and they are called multiple times before and after rendering each group. A group is one of:
- continuous sets of inline elements
- a video element
- list elements
- block elements (header, code-block, blockquote, align, indent, and direction)
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.
afterRender
event is called with generated html for you to inspect, maybe make some changes and return your modified or original html.
1 2converter.beforeRender(function(groupType, data){ 3 // ... generate your own html 4 // return your html 5}); 6converter.afterRender(function(groupType, htmlString){ 7 // modify if you wish 8 // return the html 9}); 10 11html = converter.convert(); 12
Following shows the parameter formats for beforeRender
event:
groupType | data |
---|---|
video | {op: op object } |
block | {op: op object : ops: Array<op object >} |
list | {items: Array<{item: block , innerList: list or null }> } |
inline-group | {ops: Array<op object >} |
op object
will have the following format:
1{ 2 insert: { 3 type: '' // one of 'text' | 'image' | 'video' | 'formula', 4 value: '' // some string value 5 }, 6 attributes: { 7 // ... quill delta attributes 8 } 9}
Rendering Inline Styles
If 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. quill-delta-to-html supports rendering inline styles instead. The easiest way to enable this is to pass the option inlineStyles: true
.
You can customize styles by passing an object to inlineStyles
instead:
1inlineStyles: { 2 font: { 3 'serif': 'font-family: Georgia, Times New Roman, serif', 4 'monospace': 'font-family: Monaco, Courier New, monospace' 5 }, 6 size: { 7 'small': 'font-size: 0.75em', 8 'large': 'font-size: 1.5em', 9 'huge': 'font-size: 2.5em' 10 }, 11 indent: (value, op) => { 12 var indentSize = parseInt(value, 10) * 3; 13 var side = op.attributes['direction'] === 'rtl' ? 'right' : 'left'; 14 return 'padding-' + side + ':' + indentSize + 'em'; 15 }, 16 direction: (value, op) => { 17 if (value === 'rtl') { 18 return 'direction:rtl' + ( op.attributes['align'] ? '' : '; text-align: inherit' ); 19 } else { 20 return ''; 21 } 22 } 23};
Keys 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.
Rendering Custom Blot Formats
You need to tell system how to render your custom blot by registering a renderer callback function to renderCustomWith
method before calling the convert()
method.
If 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.
Example:
1let ops = [ 2 {insert: {'my-blot': {id: 2, text: 'xyz'}}, attributes: {renderAsBlock: true|false}} 3]; 4 5let converter = new QuillDeltaToHtmlConverter(ops); 6 7// customOp is your custom blot op 8// contextOp is the block op that wraps this op, if any. 9// If, for example, your custom blot is located inside a list item, 10// then contextOp would provide that op. 11converter.renderCustomWith(function(customOp, contextOp){ 12 if (customOp.insert.type === 'my-blot') { 13 let val = customOp.insert.value; 14 return `<span id="${val.id}">${val.text}</span>`; 15 } else { 16 return 'Unmanaged custom blot!'; 17 } 18}); 19 20html = converter.convert();
customOp object
will have the following format:
1{ 2 insert: { 3 type: string //whatever you specified as key for insert, in above example: 'my-blot' 4 value: any // value for the custom blot 5 }, 6 attributes: { 7 // ... any attributes custom blot may have 8 } 9}
Advanced Custom Rendering Using Grouped Ops
If you want to do the full rendering yourself, you can do so by getting the processed & grouped ops.
1let groupedOps = converter.getGroupedOps();
Each element in groupedOps array will be an instance of the following types:
type | properties |
---|---|
InlineGroup | ops: Array<op object > |
VideoItem | op: op object |
BlockGroup | op: op object , ops: Array<op object > |
ListGroup | items: Array<ListItem > |
ListItem: {item:BlockGroup , innerList:ListGroup } | |
BlotBlock | op: op object |
BlotBlock
represents custom blots with renderAsBlock:true
property pair in its attributes
See above for op object
format.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 7/12 approved changesets -- score normalized to 5
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 26 are checked with a SAST tool
Reason
16 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-x9w5-v3q2-3rhw
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-434g-2637-qmqr
- Warn: Project is vulnerable to: GHSA-49q7-c7j4-3p7m
- Warn: Project is vulnerable to: GHSA-977x-g7h5-7qgw
- Warn: Project is vulnerable to: GHSA-f7q4-pwc6-w24p
- Warn: Project is vulnerable to: GHSA-fc9h-whq2-v747
- Warn: Project is vulnerable to: GHSA-2j2x-2gpw-g8fm
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-g4rg-993r-mgx7
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
Score
2.4
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More