@voiceflow/slate-serializer
v1.6.0
Published
Utilities for serializing slate data
Downloads
4,090
Maintainers
Readme
Slate Serializer
Utilities for converting slate data into raw text or JSX.
Installation
yarn add @voiceflow/slate-serializer @voiceflow/base-types slate
# or
npm install @voiceflow/slate-serializer @voiceflow/base-types slate
If you want to use the JSX serializer make sure to install react
.
yarn add react
# or
npm install react
Usage
You can access type guards and other extraction utilities through the main import.
import { isLinkElement, getTextCSSProperties } from '@voiceflow/react-chat';
Text Serialization
If you need the textual representation you can import the text serializer.
import { serializeToText } from '@voiceflow/react-chat/text';
const text = serializeToText(slateValue);
You can turn off encodeVariables
to avoid encoding variables in the text.
import { serializeToText } from '@voiceflow/react-chat/text';
const textWithoutVariables = serializeToText(slateValue, { encodeVariables: false });
JSX Serialization
If you want to render the result in a browser you can serialize to JSX.
import { serializeToJSX } from '@voiceflow/react-chat/jsx';
const content = <div>{serializeToJSX(slateValue)}</div>;
Markdown Serialization
If you want to render the result in a browser you can serialize to JSX.
import { serializeToMarkdown } from '@voiceflow/react-chat/markdown';
const content = <div>{serializeToMarkdown(slateValue)}</div>;