Quill Delta to Object Converter
Converts Quill's Delta format to Object (insert ops only) with properly nested lists.
This library is inspired by quill-delta-to-html.
Quickstart
Installation
npm install quill-delta-to-object
Usage
var QuillDeltaToObjectConverter = require('quill-delta-to-object').QuillDeltaToObjectConverter;
var deltaOps = [
{insert: "Hello\n"},
{insert: "This is colorful", attributes: {color: '#f00'}}
];
var converter = new QuillDeltaToObjectConverter(deltaOps);
var object = converter.convert();
Supporting Formats
Not Supported:
- Image
- Video
- Table
- Nested List
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.
Example:
let ops = [
{ insert: { bolditalic: 'my text' } },
];
let converter = new QuillDeltaToObjectConverter(ops);
converter.renderCustomWith(function(customOp, contextOp){
if (op.insert.type === 'bolditalic') {
return {
type: 'text',
value: op.insert.value,
attributes: { bold: true, italic: true },
};
}
return undefined;
});
object = converter.convert();
customOp object
will have the following format:
{
insert: {
type: string
value: any
},
attributes: {
}
}