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

quill-render

v1.0.5

Published

Renders quilljs deltas into HTML

Downloads

2,353

Readme

quill-render

Build Status

Renders a sequence of quill insert-only deltas (operational transforms) into HTML with no browser dependencies.

This is accomplished by using cheerio to build a DOM from the delta sequence.

One way to get a document's insert-only deltas is by calling Quill#getContents() in the browser.

Example

var render = require('quill-render');
render([
    {
        "attributes": {
            "bold": true
        },
        "insert": "Hi mom"
    }
]);
// => '<b>Hi mom</b>'

If you want the cheerio object instead of the HTML, use render.asDOM().

var $ = render.asDOM([...]);
// ... DOM surgery ...

Extending

quill-render exposes the functions it uses to produce markup so that you can tweak it to fit your needs. You can change the behavior of the builtin formats or create your own.

Each function is passed $ (the root cheerio object) and the value of the format.

For inline styles, return a new element. The contents of the insert will be appended as children of the element.

render.format.inline.bold = function($/*, formatValue */) {
    return $('<b>').addClass('super-important');
};
// above example would now return '<b class="super-important">Hi mom</b>'

For 'block' styles (those deltas where insert === 1 -- ie images), this will be the block container (a <p>). Append elements to it.

render.format.block.image = function($, src) {
    var img = $('<img>');
    img.attr('src', src);
    this.append(img);
};

For line styles (those deltas where insert == '\n' and the format is meant to apply to the entire line), this will be the line's container (a p.)

render.format.lineify.h1 = function(/* $, formatValue */) {
    this[0].name = 'h1'; // change the line container tag to a h1
};

You can also specify a grouping tag. When multiple lines with the same format appear is sequence, the entire group is wrapped in the group element. (ie lists)

render.format.lineify.bullet = {
    group: function($) {
        return $('<ul>'); // return the element that will be the parent of all group members
    },
    line: function() {
        this[0].name = 'li'; // make each group member a li
    }
};