Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@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!
FAQs
Plain text renderer for the Rich Text document.
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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.