Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
slate-serializers
Advanced tools
Serialize Slate JSON objects to HTML and vice versa. Define rules to modify the end result.
A collection of serializers to convert Slate JSON objects to various formats and vice versa. Designed to work in both Node.js and browser environments.
Serializers included so far:
slateToDom
slateToHtml
htmlToSlate
yarn add slate-serializers
# or
npm install slate-serializers
Example usage:
import { slateToHtml, htmlToSlate } from 'slate-serializers'
const slate = [
{
children: [
{
text: 'Heading 1',
},
],
type: 'h1',
},
{
children: [
{
text: 'Paragraph 1',
},
],
type: 'p',
},
]
const serializedToHtml = slateToHtml(slate)
// output
// <h1>Heading 1</h1><p>Paragraph 1</p>
// ...and convert back to Slate
const serializedToSlate = htmlToSlate(serializedToHtml)
Both serializers support an attributeMap
option, which maps Slate attributes to HTML attributes and vice versa. This is supported for element tags only.
const slate = [
{
children: [
{
type: 'link',
linkType: "custom",
url: 'https://github.com/thompsonsj/slate-serializers',
newTab: true,
children: [
{
text: 'slate-serializers | GitHub',
},
],
},
],
type: 'p',
}
]
const html = slateToHtml(slate,
{
attributeMap: [
{
slateAttr: 'linkType',
htmlAttr: 'data-link-type'
}
]
}
)
// output
// <p><a href="https://github.com/thompsonsj/slate-serializers" target="_blank" data-link-type="custom">slate-serializers | GitHub</a></p>
// using the same attributeMap for htmlToSlate will ensure the linkType attribute is preserved in the Slate JSON object.
const slateReserialized = htmlToSlate(html,
{
attributeMap: [
{
slateAttr: 'linkType',
htmlAttr: 'data-link-type'
}
]
}
)
slateToHtml
is a simple wrapper that runs dom-serializer
on the output from slateToDom
.
slateToDom
is made available in case you wish to work woth the DOM output yourself or run dom-serializer
using any of the available options.
Based on logic in Deserializing | Serializing | Slate.
htmlparser2 is used to parse HTML instead of the DOMHandler
object. Rationale:
htmlparser2
is the fastest HTML parser.Based on logic in HTML | Serializing | Slate.
TLDR: contributors can format commit messages in any way, maintainers should use conventional commits.
This repository uses conventional commits.
Conventional commits are not enforced. General guidance:
Run npx cz
instead of git commit
to lint commit messages using @commitlint/cli.
FAQs
This package has been split into separate packages.
The npm package slate-serializers receives a total of 2,736 weekly downloads. As such, slate-serializers popularity was classified as popular.
We found that slate-serializers 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.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.