
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
datocms-structured-text-to-plain-text
Advanced tools
Convert DatoCMS Structured Text field to plain text
Plain text renderer for the Structured Text document.
Using npm:
npm install datocms-structured-text-to-plain-text
Using yarn:
yarn add datocms-structured-text-to-plain-text
import { render } from 'datocms-structured-text-to-plain-text';
const structuredText = {
value: {
schema: 'dast',
document: {
type: 'root',
children: [
{
type: 'heading',
level: 1,
children: [
{
type: 'span',
value: 'This\nis a\ntitle!',
},
],
},
],
},
},
};
render(structuredText); // -> "This is a title!"
You can also pass custom renderers for itemLink
, inlineItem
, block
as optional parameters like so:
import { render } from 'datocms-structured-text-to-plain-text';
const graphqlResponse = {
value: {
schema: 'dast',
document: {
type: 'root',
children: [
{
type: 'paragraph',
children: [
{
type: 'span',
value: 'A ',
},
{
type: 'itemLink',
item: '344312',
children: [
{
type: 'span',
value: 'record hyperlink',
},
],
},
{
type: 'span',
value: ' and an inline record: ',
},
{
type: 'inlineItem',
item: '344312',
},
],
},
{
type: 'block',
item: '812394',
},
],
},
},
blocks: [
{
id: '812394',
image: { url: 'http://www.datocms-assets.com/1312/image.png' },
},
],
links: [{ id: '344312', title: 'Foo', slug: 'foo' }],
};
const options = {
renderBlock({ record }) {
return `[Image ${record.image.url}]`;
},
renderInlineRecord({ record, adapter: { renderNode } }) {
return `[Inline ${record.slug}]${children}[/Inline]`;
},
renderLinkToRecord({ record, children, adapter: { renderNode } }) {
return `[Link to ${record.slug}]${children}[/Link]`;
},
};
render(document, options);
// -> A [Link to foo]record hyperlink[/Link] and an inline record: [Inline foo]Foo[/Inline]
// [Image http://www.datocms-assets.com/1312/image.png]
FAQs
Convert DatoCMS Structured Text field to plain text
The npm package datocms-structured-text-to-plain-text receives a total of 12,301 weekly downloads. As such, datocms-structured-text-to-plain-text popularity was classified as popular.
We found that datocms-structured-text-to-plain-text demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 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.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.