Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

draftjs-to-html

Package Overview
Dependencies
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

draftjs-to-html

A library for draftjs to html conversion.

  • 0.9.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
202K
increased by9.67%
Maintainers
1
Weekly downloads
 
Created

What is draftjs-to-html?

The draftjs-to-html npm package is a utility that converts Draft.js editor content to HTML. It is particularly useful for applications that use Draft.js for rich text editing and need to render the content as HTML for display or storage.

What are draftjs-to-html's main functionalities?

Convert Draft.js ContentState to HTML

This feature allows you to convert the Draft.js ContentState to HTML. The code sample demonstrates how to get the current content from the editor state, convert it to a raw content state, and then convert it to HTML using the draftjs-to-html package.

const draftToHtml = require('draftjs-to-html');
const { convertToRaw } = require('draft-js');

const contentState = editorState.getCurrentContent();
const rawContentState = convertToRaw(contentState);
const html = draftToHtml(rawContentState);
console.log(html);

Custom Block Rendering

This feature allows you to define custom rendering for specific block types. The code sample shows how to render 'atomic' blocks with a custom HTML structure.

const draftToHtml = require('draftjs-to-html');
const { convertToRaw } = require('draft-js');

const contentState = editorState.getCurrentContent();
const rawContentState = convertToRaw(contentState);
const html = draftToHtml(rawContentState, {
  blockRenderers: {
    'atomic': (block) => `<div class='custom-atomic'>${block.text}</div>`
  }
});
console.log(html);

Custom Inline Style Rendering

This feature allows you to define custom rendering for inline styles. The code sample demonstrates how to render 'BOLD' styles as <strong> tags.

const draftToHtml = require('draftjs-to-html');
const { convertToRaw } = require('draft-js');

const contentState = editorState.getCurrentContent();
const rawContentState = convertToRaw(contentState);
const html = draftToHtml(rawContentState, {
  styleToHTML: (style) => {
    if (style === 'BOLD') {
      return <strong />;
    }
    return null;
  }
});
console.log(html);

Other packages similar to draftjs-to-html

FAQs

Package last updated on 10 Dec 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