Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
@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 16 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
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.