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:
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)
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.You may get better results passing the enforceTopLevelPTags
option.
slateToHtml(slate, {enforceTopLevelPTags: true})
Objects in the Slate JSON can have no type (e.g. p
) and contain a number of children. This causes issues for the serializer, which renders each child at the top of the DOM. Example: Paragraph 1.Paragraph 2.
. Complexity is increased when text marks are involved such as u
, strong
and i
.
To avoid this, enforceTopLevelPTags
ensures any top level objects without a type are assigned as a p
tag. Example: <p>Paragraph 1.</p><p>Paragraph 2.</p>
.
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.