Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@contentful/rich-text-plain-text-renderer
Advanced tools
Plain text renderer for the Rich Text document.
@contentful/rich-text-plain-text-renderer is an npm package that provides functionality to convert Contentful's rich text documents into plain text. This can be useful for scenarios where you need to extract and manipulate text content without any formatting or HTML tags.
Convert Rich Text to Plain Text
This feature allows you to convert a Contentful rich text document into a plain text string. The code sample demonstrates how to use the `documentToPlainTextString` function to achieve this.
const { documentToPlainTextString } = require('@contentful/rich-text-plain-text-renderer');
const richTextDocument = {
nodeType: 'document',
content: [
{
nodeType: 'paragraph',
content: [
{
nodeType: 'text',
value: 'Hello, world!',
marks: [],
data: {}
}
],
data: {}
}
],
data: {}
};
const plainText = documentToPlainTextString(richTextDocument);
console.log(plainText); // Output: 'Hello, world!'
The `html-to-text` package converts HTML content into plain text. It is more general-purpose compared to @contentful/rich-text-plain-text-renderer, which is specifically designed for Contentful's rich text format. However, `html-to-text` can be used for a wider range of HTML content.
The `turndown` package is a highly customizable HTML to Markdown converter. While it focuses on converting HTML to Markdown, it can also be used to strip HTML tags and extract plain text. This makes it a versatile tool for text extraction, though it is not specifically tailored for Contentful's rich text format.
The `sanitize-html` package is used to clean up and sanitize HTML content by removing unwanted tags and attributes. While its primary purpose is to sanitize HTML, it can also be configured to strip all tags, effectively converting HTML to plain text. This package offers more control over the sanitization process compared to @contentful/rich-text-plain-text-renderer.
Plain text renderer for the Rich Text document.
Using npm:
npm install @contentful/rich-text-plain-text-renderer
Using yarn:
yarn add @contentful/rich-text-plain-text-renderer
import { documentToPlainTextString } from '@contentful/rich-text-plain-text-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: {}
},
],
},
]
};
documentToPlainTextString(document); // -> Hello world!
14.1.2 (2020-11-02)
mark
property from extra props (20ec641)FAQs
Plain text renderer for the Rich Text document.
The npm package @contentful/rich-text-plain-text-renderer receives a total of 111,106 weekly downloads. As such, @contentful/rich-text-plain-text-renderer popularity was classified as popular.
We found that @contentful/rich-text-plain-text-renderer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.