https://github.com/klimonov/rich-text-to-html
https://github.com/klimonov/rich-text-to-html
contentful javascript rich-text
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/klimonov/rich-text-to-html
- Owner: Klimonov
- Created: 2022-03-19T08:11:58.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-03-19T14:01:38.000Z (about 3 years ago)
- Last Synced: 2025-02-25T08:47:28.282Z (2 months ago)
- Topics: contentful, javascript, rich-text
- Language: JavaScript
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# rich-text-to-html
HTML renderer for the Contentful rich text field type **with Embed**.
## Installation
```sh
$ npm install rich-text-to-html
```## Usage
```javascript
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"
}
}
}
}
}
]
};
richTextToHtmlString(document); // ->Casino ads
custom text
![]()
```