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

rich-text-to-html

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rich-text-to-html

return html string from contentful rich text fieild

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-92.86%
Maintainers
1
Weekly downloads
 
Created
Source

rich-text-to-html

HTML renderer for the Contentful rich text field type with Embed.

Installation

$ npm install rich-text-to-html

Usage

import richTextToHtmlString from 'rich-text-to-html';
const document = {
    nodeType: "document",
    data: {},
    content: [
        {
            nodeType: "heading-2",
            content: [
                {
                    nodeType: "text",
                    value: "Block title",
                    marks: [],
                    data: {}
                }
            ],
            data: {}
        },
        {
            nodeType: "paragraph",
            content: [
                {
                    nodeType: "text",
                    value: "custom text",
                    marks: [],
                    data: {}
                }
            ],
            data: {}
        },
        {
            nodeType: "embedded-asset-block",
            content: [],
            data: {
                target: {
                    metadata: {
                        tags: []
                    },
                    sys: {
                        space: {
                            sys: {
                                type: "Link",
                                linkType: "Space",
                            }
                        },
                        type: "Asset",
                        createdAt: "2022-03-03T13:21:41.509Z",
                        updatedAt: "2022-03-03T13:21:41.509Z",
                        environment: {
                            sys: {
                                id: "master",
                                type: "Link",
                                linkType: "Environment"
                            }
                        },
                        revision: 1,
                        locale: "en-US"
                    },
                    fields: {
                        title: "Banner",
                        description: "",
                        file: {
                            url: "//images.ctfassets.net/.../image.webp",
                            details: {
                                size: 16652,
                                image: {
                                    width: 940,
                                    height: 150
                                }
                            },
                            fileName: "image.webp",
                            contentType: "image/webp"
                        }
                    }
                }
            }
        },
        {
            nodeType: "paragraph",
            content: [
                {
                    nodeType: "text",
                    value: "custom text",
                    marks: [],
                    data: {}
                }
            ],
            data: {}
        }
    ]
};
richTextToHtmlString(document); // -> <h2>Casino ads</h2><p>custom text</p><img alt="Banner" src="https://images.ctfassets.net/.../image.webp"><p>custom text</p>

Keywords

FAQs

Package last updated on 19 Mar 2022

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