Skip to content

Latest commit

 

History

History
65 lines (42 loc) · 1.44 KB

File metadata and controls

65 lines (42 loc) · 1.44 KB

Slate Serializer

Utilities for converting slate data into raw text or JSX.

Installation

yarn add @voiceflow/slate-serializer @voiceflow/dtos-interact slate
# or
npm install @voiceflow/slate-serializer @voiceflow/dtos-interact 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>;