A library to convert Slate models to their slate-hyperscript representation.
You can use @zarv1k/slate-hyperprint
as a library to:
- Improve the output of unit tests by comparing hyperscript strings instead of JSON values.
- Facilitate debugging and console logging of Slate values.
See the online demo, that converts a Slate JSON representation to a Slate hyperscript representation.
yarn add @zarv1k/slate-hyperprint [--dev]
import Slate from 'slate';
import hyperprint from '@zarv1k/slate-hyperprint';
console.log(
hyperprint(
Slate.Value.create({
document: Slate.Document.create({
nodes: [
Slate.Block.create({
type: 'paragraph',
data: { a: 1 },
nodes: [
Slate.Text.create('Hello')
]
}
)]
})
})
)
);
// <value>
// <document>
// <paragraph a={1}>
// Hello
// </paragraph>
// </document>
// </value>
hyperprint.log(...)
// Equivalent to console.log(hyperprint(...))
slate-hyperprint
accepts an option object:
hyperprint(value, options)
preserveData: boolean = false
True to print Slate Value's datapreserveKeys: boolean = false
True to print node keysstrict: boolean = false
True to preserve empty texts and other things that the formatting would otherwise omit. Useful when using hyperprint compare values in tests, because the output is stricter.prettier: Object = { semi: false, singleQuote: true, tabWidth: 2 }
Prettier config to use when formatting the output JSX.
yarn test
yarn build
- Original library repo
- The React equivalent react-element-to-jsx-string is and will remain a great source of inspiration.