You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
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.6.0
Source
npm
Version published
Weekly downloads
228K
2.06%
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 05 Feb 2017

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