Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
sanity-plugin-html-to-portable-text
Advanced tools
Readme
HTML to Portable Text
This plugin provides a custom input component which converts HTML
into Portable Text on the fly.
Sanity
is using the Portable Text
-format whenever you use the block
-type along with the WYSIWYG
-Block Content Editor.
Since HTML to Portable Text
does a on-the-fly-conversion, it does not mirror nor persist the HTML
to your schema. This is a deliberate design decision, for one, to avoid redundancy, secondly, to avoid inconsistant data, and thirdly, it would defeat the whole purpose of the Portable Text
.
You may want to linkHTML to Portable Text
with a block
-field to persist the corresponding Portable Text
] to your schema
.
Install the Sanity Plugin HTML to Portable Text
with the sanity CLI
sanity install sanity-plugin-html-to-portable-text
To make it available, just add a field of htmlPortableText
-type to your fields-array and reference another field of block
-type.
fields: [
{
name: 'htmlToArticleBody',
title: 'HTML to Article Body',
type: 'htmlToProtableText',
options: { refblock: 'articleBody' },
{
name: 'articleBody',
title: 'Article Body',
type: 'array',
of: [ { type: 'block' } ]
}
]
You can configure styles
, markers
, lists
, decorators
, etc. as you are used to. Only make sure to have it in sync for the htmlToProtableText
-type as well as the block
-type.
fields: [
{
name: 'htmlToArticleBody',
title: 'HTML to Article Body',
type: 'htmlToProtableText',
options: {
refblock: 'articleBody',
styles: [
// allow only unstyled, H1 and H2
{ title: 'Unstyled', value: 'normal' },
{ title: 'H1', value: 'h1' },
{ title: 'H2', value: 'h2' },
]
},
{
name: 'articleBody',
title: 'Article Body',
type: 'array',
of: [
{
type: 'block',
styles: [
// make sure to sync the same definitions here
{ title: 'Unstyled', value: 'normal' },
{ title: 'H1', value: 'h1' },
{ title: 'H2', value: 'h2' },
]
}
]
}
]
refblock
reference a valid block. Otherwise, sanity will complain about invalid field
.styles
in options according to styles
of the refernced block, otherwise conversion back and forth will bear different results.fields: [
{
name: 'htmlToArticleBody',
title: 'HTML to Article Body',
type: 'htmlToProtableText',
options: {
refblock: 'articleBody',
// Disallow styles
styles: [],
// Disallow lists
lists: [],
marks: {
// Only allow these decorators
decorators: [
{ title: 'Bold', value: 'strong' },
{
title: 'Superscript',
value: 'sup',
// blockEditor not needed here
},
],
// disallow links
annotations: []
}
},
{
name: 'articleBody',
title: 'Article Body',
type: 'array',
of: [
{
type: 'block',
styles: [],
lists: [],
marks: {
decorators: [
{ title: 'Bold', value: 'strong' },
{
title: 'Superscript',
value: 'sup',
// Define custom icon and renderer for the blockEditor
blockEditor: {
icon: () => <div>⤴</div>,
render: ({ children }) => <span><sup>{children}</sup></span>
}
},
],
annotations: []
}
]
}
]
HTML
into Portable Text on the flyblock
-field, persist the corresponding Portable Text to your schema
unit tests
, since this is a delicate functionalitystyles
in options gets obsolete
refblock
references an existing block
-type fieldFAQs
Sanity custom input plugin to convert HTML to Portable Text
The npm package sanity-plugin-html-to-portable-text receives a total of 132 weekly downloads. As such, sanity-plugin-html-to-portable-text popularity was classified as not popular.
We found that sanity-plugin-html-to-portable-text demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).