New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

html-to-prosemirror

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

html-to-prosemirror

Takes HTML and outputs ProseMirror compatible JSON

  • 1.0.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
26
increased by4%
Maintainers
1
Weekly downloads
 
Created
Source

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 --save

Usage

const Renderer = require("html-to-prosemirror").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);

Keywords

FAQs

Package last updated on 29 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc