
Security News
Another Round of TEA Protocol Spam Floods npm, But It’s Not a Worm
Recent coverage mislabels the latest TEA protocol spam as a worm. Here’s what’s actually happening.
@contentful/rich-text-html-renderer
Advanced tools
HTML renderer for the Contentful rich text field type.
Using npm:
npm install @contentful/rich-text-html-renderer
Using yarn:
yarn add @contentful/rich-text-html-renderer
import { documentToHtmlString } from '@contentful/rich-text-html-renderer';
const document = {
nodeType: 'document',
content: [
{
nodeType: 'paragraph',
content: [
{
nodeType: 'text',
value: 'Hello world!',
marks: [],
},
],
},
],
};
documentToHtmlString(document); // -> <p>Hello world!</p>
import { documentToHtmlString } from '@contentful/rich-text-html-renderer';
const document = {
nodeType: 'document',
content: [
{
nodeType: 'paragraph',
content: [
{
nodeType: 'text',
value: 'Hello',
marks: [{ type: 'bold' }],
},
{
nodeType: 'text',
value: ' world!',
marks: [{ type: 'italic' }],
},
],
},
],
};
documentToHtmlString(document); // -> <p><b>Hello</b><u> world!</u></p>
You can also pass custom renderers for both marks and nodes as an optional parameter like so:
import { BLOCKS, MARKS } from '@contentful/rich-text-types';
import { documentToHtmlString } from '@contentful/rich-text-html-renderer';
const document = {
nodeType: 'document',
data: {},
content: [
{
nodeType: 'paragraph',
data:{},
content: [
{
nodeType: 'text',
value: 'Hello',
marks: [{ type: 'bold' }],
data: {}
},
{
nodeType: 'text',
value: ' world!',
marks: [{ type: 'italic' }]
data: {}
},
],
},
]
};
const options = {
renderMark: {
[MARKS.BOLD]: text => `<custom-bold>${text}<custom-bold>`
},
renderNode: {
[BLOCKS.PARAGRAPH]: (node, next) => `<custom-paragraph>${next(node.content)}</custom-paragraph>`
}
}
documentToHtmlString(document, options);
// -> <custom-paragraph><custom-bold>Hello</custom-bold><u> world!</u></custom-paragraph>
Last, but not least, you can pass a custom rendering component for an embedded entry:
import { BLOCKS } from '@contentful/rich-text-types';
import { documentToHtmlString } from '@contentful/rich-text-html-renderer';
const document = {
nodeType: 'document',
data: {},
content: [
{
nodeType: 'embedded-entry-block',
data: {
target: (...)Link<'Entry'>(...);
},
},
]
};
const options = {
renderNode: {
[BLOCKS.EMBEDDED_ENTRY]: (node) => `<custom-component>${customComponentRenderer(node)}</custom-component>`
}
}
documentToHtmlString(document, options);
// -> <custom-component>(...)Link<'Entry'>(...)</custom-component>
The renderNode keys should be one of the following BLOCKS and INLINES properties as defined in @contentful/rich-text-types:
BLOCKS
DOCUMENTPARAGRAPHHEADING_1HEADING_2HEADING_3HEADING_4HEADING_5HEADING_6UL_LISTOL_LISTLIST_ITEMQUOTEHREMBEDDED_ENTRYEMBEDDED_ASSETEMBEDDED_RESOURCEINLINES
EMBEDDED_ENTRY (this is different from the BLOCKS.EMBEDDED_ENTRY)HYPERLINKENTRY_HYPERLINKASSET_HYPERLINKThe renderMark keys should be one of the following MARKS properties as defined in @contentful/rich-text-types:
BOLDITALICUNDERLINECODESUPERSCRIPTSUBSCRIPTThe `rich-text-to-html` package provides similar functionality for converting rich text documents to HTML. It offers a straightforward API but may not be as tightly integrated with Contentful's specific rich text format as @contentful/rich-text-html-renderer.
The `draft-js-export-html` package is used to convert Draft.js editor content to HTML. While it is not specifically designed for Contentful's rich text format, it offers robust customization options and can be adapted for various rich text needs.
The `html-to-draftjs` package converts HTML to Draft.js content state. It serves the opposite purpose but can be used in conjunction with Draft.js to achieve similar results. It is not specifically tailored for Contentful's rich text format.
FAQs
HTML renderer for the Contentful rich text field type.
The npm package @contentful/rich-text-html-renderer receives a total of 194,484 weekly downloads. As such, @contentful/rich-text-html-renderer popularity was classified as popular.
We found that @contentful/rich-text-html-renderer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?

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.

Security News
Recent coverage mislabels the latest TEA protocol spam as a worm. Here’s what’s actually happening.

Security News
PyPI adds Trusted Publishing support for GitLab Self-Managed as adoption reaches 25% of uploads

Research
/Security News
A malicious Chrome extension posing as an Ethereum wallet steals seed phrases by encoding them into Sui transactions, enabling full wallet takeover.