Skip to content
This repository was archived by the owner on Nov 18, 2017. It is now read-only.

Make it possible to serialize editor state automatically - #5

Open
mxstbr wants to merge 1 commit into
switch-to-blocksfrom
serializtaion
Open

Make it possible to serialize editor state automatically#5
mxstbr wants to merge 1 commit into
switch-to-blocksfrom
serializtaion

Conversation

@mxstbr

@mxstbr mxstbr commented May 7, 2017

Copy link
Copy Markdown
Contributor

Rather than manually adding serialization rules for this plugin users can now do this:

import { Html } from 'slate';
import MentionPlugin from 'slate-mentions';

// Create the plugin as usual
const mentions = MentionPlugin({
  Mention: MentionComponent,
  Suggestions: SuggestionsComponent,
});

const { serialize } = new Html({
  // Add the mentions serialization rules after any of your custom ones
  rules: [...mentions.serializationRules]
});

// Get your current editor state as HTML 🎉
serialize(editor.state);

// You can also get your current editor state as React components:
serialize(editor.state, { render: false });

The serialize-to-react-component-thing seems like a much better option for rendering messages, rather than rendering thousands of read-only editors. Am I right in assuming that's a better approach @ianstormtaylor?

@mxstbr

mxstbr commented May 7, 2017

Copy link
Copy Markdown
Contributor Author

I'm unsure if this actually makes sense, given that when you render a serialized mention you might want to render e.g. a link and not just a span. Might have to rethink this...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant