slate-mentions icon indicating copy to clipboard operation
slate-mentions copied to clipboard

Make it possible to serialize editor state automatically

Open mxstbr opened this issue 7 years ago • 1 comments

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 avatar May 07 '17 13:05 mxstbr

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...

mxstbr avatar May 07 '17 13:05 mxstbr