|
Download react-page/docs/utils.md from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.8 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-page/docs/utils.md
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-page/docs/utils.md
-
curl -L -o utils.md https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-page/docs/utils.md
1.8 kB
createValue: create a Value object
createValue can be used to create a value for the editor. This is useful if you want to
populate an empty editor with a default value.
The advantage over writing a Value manually is that you don't need to write ids
and that it provides some shortcuts.
You need to pass in the language and your cellPlugins as second argument:
import { createValue } from '@react-page/editor';
const partialValue = {
rows: [
// a row with two cells:
[
{
plugin: imagePlugin.id,
data: {
src: 'http://path/to/image',
},
},
{
plugin: imagePlugin.id,
data: {
src: 'http://path/to/other-image',
},
},
],
// a row with one cell
[
// a cell with rich text
{
plugin: slatePlugin.id,
data: slatePlugin.createData((def) => ({
children: [
{
plugin: def.plugins.headings.h1,
children: ['hello'],
},
{
plugin: def.plugins.paragraphs.paragraph,
children: ['Hello world'],
},
],
})),
},
],
],
};
const value = createValue(partialValue, {
lang: 'en',
cellPlugins: yourCellPlugins,
});
getTextContents: get raw text contents
Can be used to extract plaintext from the editors value.
You need to pass in the language and your cellPlugins as second argument:
import { getTextContents } from '@react-page/editor';
const contents = getTextContents(value, {
lang: 'en',
cellPlugins: yourCellPlugins,
});
// contents is an array of strings
Full example: