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

@contentful/rich-text-html-renderer

Package Overview
Dependencies
Maintainers
5
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@contentful/rich-text-html-renderer

HTML renderer for the Contentful rich text field type.

17.1.0
latest
Source
npmnpm
Version published
Weekly downloads
180K
4.7%
Maintainers
5
Weekly downloads
 
Created

What is @contentful/rich-text-html-renderer?

@contentful/rich-text-html-renderer is an npm package that allows you to convert Contentful's rich text document format into HTML. This is particularly useful for rendering rich text content stored in Contentful CMS into web pages.

What are @contentful/rich-text-html-renderer's main functionalities?

Rendering Rich Text to HTML

This feature allows you to convert a Contentful rich text document into an HTML string. The code sample demonstrates how to use the `documentToHtmlString` function to achieve this.

const { documentToHtmlString } = require('@contentful/rich-text-html-renderer');
const richTextDocument = {
  nodeType: 'document',
  content: [
    {
      nodeType: 'paragraph',
      content: [
        {
          nodeType: 'text',
          value: 'Hello, world!',
          marks: [],
          data: {}
        }
      ],
      data: {}
    }
  ],
  data: {}
};
const htmlString = documentToHtmlString(richTextDocument);
console.log(htmlString); // Outputs: <p>Hello, world!</p>

Customizing HTML Output

This feature allows you to customize the HTML output by providing options to the `documentToHtmlString` function. The code sample shows how to add a custom class to paragraph elements.

const { documentToHtmlString } = require('@contentful/rich-text-html-renderer');
const richTextDocument = {
  nodeType: 'document',
  content: [
    {
      nodeType: 'paragraph',
      content: [
        {
          nodeType: 'text',
          value: 'Hello, world!',
          marks: [],
          data: {}
        }
      ],
      data: {}
    }
  ],
  data: {}
};
const options = {
  renderNode: {
    'paragraph': (node, next) => `<p class="custom-class">${next(node.content)}</p>`
  }
};
const htmlString = documentToHtmlString(richTextDocument, options);
console.log(htmlString); // Outputs: <p class="custom-class">Hello, world!</p>

Other packages similar to @contentful/rich-text-html-renderer

FAQs

Package last updated on 15 Jul 2025

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