Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@sanity/block-content-to-tree
Advanced tools
Converts the flat Sanity block content structure into a generic tree structure for easier transformation into other formats.
Converts the flat Sanity block content structure into a generic tree structure for easier transformation into other formats (HTML, React etc).
npm install --save @sanity/block-content-to-tree
// The flat block content structure
const data = {
"_type": "block",
"style": "normal",
"spans": [
{
"_type": "span",
"text": "String with an ",
"marks": []
},
{
"_type": "span",
"text": "italicized",
"marks": [
"em"
]
},
{
"_type": "span",
"text": " word.",
"marks": []
}
]
}
// Now convert it with block-content-to-tree
const BlockContentToTree = require('@sanity/block-content-to-tree')
const blockContentToTree = new BlockContentToTree()
const tree = blockContentToTree.convert(data)
This will result in the variable tree
being:
{
type: 'block',
style: 'normal',
content: [
'String with an ',
{
type: 'span',
attributes: {},
mark: 'em',
content: [
'italicized'
]
},
' word.'
]
}
{
type: 'block',
style: 'normal' // Text style
mark: 'em', // Mark indicating all content is wrapped in bold.
content: [
'Hello world! ', // Span with no marks or attributes (plain text).
{
type: 'span',
// Data attributes for this span
attributes: {link: {href: 'http://...'}},
mark: 'strong',
// The text content for the span
// Always an array with a single plain text.
// An array to keep format consistent with block.content.
content: [
'I am a link!'
]
}
]
}
Root element
{
type: 'list',
itemStyle: 'bullet' // The list style
// Items are blocks (see above)
items: [
{block},
{block}
]
}
{
type: 'author' // Whatever, but never 'block' (built in type)
attributes: { // Custom attributes for the type
name: 'John Ronald Reuel Tolkien',
}
}
Please see the tests.
MIT-licensed
FAQs
Converts the flat Sanity block content structure into a generic tree structure for easier transformation into other formats.
The npm package @sanity/block-content-to-tree receives a total of 3 weekly downloads. As such, @sanity/block-content-to-tree popularity was classified as not popular.
We found that @sanity/block-content-to-tree demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 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
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.