Nit-Picking Magistrate

    html-to-prosemirror-js

    1.0.0 • Public • Published

    HTML to Prosemirror (JS)

    (This package is based on html-to-prosemirror, which was originally written for PHP.)

    Takes HTML and outputs ProseMirror JSON.

    Installation

    npm install html-to-prosemirror-js --save

    Usage

    const Renderer = require("html-to-prosemirror-js").Renderer;
     
    const renderer = new Renderer();
     
    console.log(
        JSON.stringify(
            renderer.render(`<p>Example Text</p>`)
        )
    );
    /*
        {
            type: "doc",
            content: [
                {
                    type: "paragraph",
                    content: [
                        {
                            type: "text",
                            text: "Example Text"
                        }
                    ]
                }
            ]
        }
    */

    Supported Nodes

    • BulletList
    • CodeBlock
    • CodeBlockWrapper (with pre)
    • HardBreak
    • Heading
    • Image (different from the scrumpy's implementations)
    • ListItem
    • OrderedList
    • Paragraph

    Supported Marks

    • Bold
    • Code
    • Italic
    • Link

    Custom Nodes

    Define your node as a class -

    const Node = require("html-to-prosemirror").Node;
     
    class CustomNode extends Node {
        matching () {
            return this.DOMNode.nodeName === "USER"; // uses `jsdom` library
        }
     
        data () {
            return {
                type: "user",
                attrs: {
                    id: this.DOMNode.getAttribute("data-id")
                }
            };
        }
    }

    Feed it to renderer instance -

    renderer.addNode(CustomNode);

    Install

    npm i html-to-prosemirror-js

    DownloadsWeekly Downloads

    2

    Version

    1.0.0

    License

    ISC

    Unpacked Size

    29.8 kB

    Total Files

    29

    Last publish

    Collaborators

    • envolt