0.0.6 • Published 3 years ago

quill-delta-to-object v0.0.6

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
3 years ago

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;

// TypeScript / ES6:
// import { QuillDeltaToObjectConverter } from 'quill-delta-to-object'; 

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);

// customOp is your custom blot op
// contextOp is the block op that wraps this op, if any. 
// If, for example, your custom blot is located inside a list item,
// then contextOp would provide that op. 
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 //whatever you specified as key for insert, in above example: 'bolditalic'
        value: any // value for the custom blot  
    }, 
    attributes: {
        // ... any attributes custom blot may have
    }
}
0.0.5

3 years ago

0.0.6

3 years ago

0.0.3

3 years ago

0.0.4

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago