npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

quilljs-parser

v1.0.14

Published

Parse QuillJS delta object into easy-to-use paragraph object.

Downloads

10,360

Readme

npm Travis (.org) GitHub last commit GitHub issues NPM npm

QuillJS Parser

Transform your QuillJS contents into an easier-to-use paragraph format.

Installation

You can install QuillJS Parser with npm.

npm i --save quilljs-parser

How Do I Use It?

Call the getContents() method of the Quill editor instance to retrieve the contents of the editor in Delta format. Then, call the parseQuillDelta() function of the QuillJS Parser package, passing in the raw Quill delta. The parseQuillDelta() function will return an easier-to-use paragraph version of the Delta.

const rawQuillDelta = quillInstance.getContents();
const parsedQuill = quillParser.parseQuillDelta(rawQuillDelta);

What Does the Package Do?

This package transforms the content of a QuillJS editor into an easy-to-work-with paragraph format.

By default, a QuillJS editor outputs its content in the Quill delta format. While the delta format works great for a browser-based editor like Quill, it's not the most convenient data format if you'd like to generate other types of documents (e.g., Word or PDF) from Quill's contents.

QuillJS Parser will transform a QuillJS delta into a more convenient paragraph-based format.

How Does It Work?

QuillJS outputs a delta with a format like the following:

ops: [{
    insert: 'Hello, how are you?'
},{
    insert: 'The First Major Section'
},{
    insert: '\n',
    attributes: { header: 1 }
},{
    insert: 'We are writing some '
},{
    insert: 'bolded text',
    attributes: { bold: true }
},{
    insert: '\n'
}]

QuillJS Parser will transform a quill Delta into an easier-to-work-with paragraph format, like the one below:

paragraphs: [{
    textRuns: [{
        text: 'Hello, how are you?'
    }]
},{
    textRuns: [{
        text: 'The First Major Section'
    }],
    attributes: {
        header: 1
    }
},{
    textRuns: [{
        text: 'We are writing some '
    },{
        text: 'bolded text',
        attributes: { bold: true }
    }]
},{
    textRuns: []
}]

The Paragraph Format

A parsed QuillJS document is composed entirely of paragraphs. Each paragraph must contain either a textRuns property or an embed property, which indicates the content of the paragraph. A paragraph may also contain an attributes property, which indicates the formatting of the paragraph.

textRuns

In a simple sense, a text run is just a string of characters within a paragraph. If the text content of a paragraph has no formatting (.e.g, bolded or italicized text), then the paragraph will contain a single text run. If, however, the text in a paragraph contains formatting, then the paragraph will be composed of two or more text runs.

For example, consider the following paragraph:

I am building a new package in Javascript. This package will be open source, and it will help developers process the text entered into a QuillJS editor.

Because this paragraph contains no formatting, the textRuns property of the paragraph object will contain a single text run, as seen below.

paragraphs: [{
    textRuns: [{
        text: 'I am building a new package in Javascript. This package will be open source, and it will help developers process the text entered into a QuillJS editor.'
    }]
}]

Next, consider the same paragraph with formatting:

I am building a new package in Javascript. This package will be open source, and it will help developers process the text entered into a QuillJS editor.

Now, the textRuns property of the paragraph object will contain 3 runs to reflect that "open source" is bold.

paragraphs: [{
    textRuns: [{
        text: 'I am building a new package in Javascript. This package will be '
    },{
        text: 'open source',
        attributes: { bold: true }
    },{
        text: ', and it will help developers process the text entered into a QuillJS editor.'
    }]
}]

embed

The other type of content that a paragraph object can contain is an embed. An embed is an object with either a video property or an image property. Both values of the property must be a string.

Note: A QuillJS embed can also be a formula, but the parser treats formula embeds as text runs (because a formula can run inline with a paragraph), so they are simply inserted into the textRuns property of the paragraph.

attributes

Finally, a paragraph can also have an attributes property. This property indicates what type of paragraph-level formatting has been applied. For instance, a header is a paragraph that is formatted as a header. Similarly, a bullet point is a paragraph that is formatted as a bullet point. An example of a paragraph with formatting is shown below.

paragraphs: [{
    textRuns: [{
        text: 'I am a bullet point.',
    }],
    attributes: { list: 'bullet' }
},{
    textRuns: [{
        text: 'I am also a bullet point, but I have '
    },{
        text: 'underlined text',
        attributes: { underline: true }
    },{
        text: ' included in my paragraph.'
    }],
    attributes: { list: 'bullet' }
}]