@yoopta/exports
v6.0.2
Published
Serialize/deserialize exports in different formats for Yoopta-Editor
Readme
@yoopta/exports
Export and import Yoopta content in different formats. Supports HTML, Markdown, and plain text. Use with the editor instance from createYooptaEditor; content is read via editor.getEditorValue() and set via editor.setEditorValue().
Installation
yarn add @yoopta/exportsUsage
Create the editor with createYooptaEditor({ plugins, marks }) and pass the editor (not plugins) to the component. Use the editor instance for get/set value.
HTML
import { useMemo } from 'react';
import YooptaEditor, { createYooptaEditor } from '@yoopta/editor';
import { html } from '@yoopta/exports';
const Editor = () => {
const editor = useMemo(() => createYooptaEditor({ plugins: PLUGINS, marks: MARKS }), []);
const deserializeHTML = () => {
const content = html.deserialize(editor, '<h1>First title</h1>');
editor.setEditorValue(content);
};
const serializeHTML = () => {
const data = editor.getEditorValue();
const htmlString = html.serialize(editor, data);
console.log(htmlString);
};
return (
<div>
<button onClick={deserializeHTML}>Load from HTML</button>
<button onClick={serializeHTML}>Export to HTML</button>
<YooptaEditor editor={editor} onChange={() => {}} />
</div>
);
};Markdown
import { markdown } from '@yoopta/exports';
const deserializeMarkdown = () => {
const value = markdown.deserialize(editor, '# First title');
editor.setEditorValue(value);
};
const serializeMarkdown = () => {
const data = editor.getEditorValue();
const md = markdown.serialize(editor, data);
console.log(md);
};Plain text
import { plainText } from '@yoopta/exports';
const deserializeText = () => {
const value = plainText.deserialize(editor, 'Some plain text');
editor.setEditorValue(value);
};
const serializeText = () => {
const data = editor.getEditorValue();
const text = plainText.serialize(editor, data);
console.log(text);
};API
html.deserialize(editor, htmlString)— HTML string → Yoopta contenthtml.serialize(editor, content)— Yoopta content → HTML stringmarkdown.deserialize(editor, markdownString)— Markdown → Yoopta contentmarkdown.serialize(editor, content)— Yoopta content → Markdown stringplainText.deserialize(editor, text)— Plain text → Yoopta contentplainText.serialize(editor, content)— Yoopta content → plain text
