draft-js-utils
draft-js-utils copied to clipboard
[draft-js-export-markdown] Add option for custom entity render function
I want to support mentions in my app, using the plugin: https://www.draft-js-plugins.com/plugin/mention
It adds a type of entities that are currently not handled, thus not rendered in markdown. That's why I added the possibility to pass a function as an option to render an entity.
Here is an example how it can be used:
// Used in editor to export mention entity as markdown-compatible string "@id"
export const renderMentionMarkdown = (_content: string, e: EntityInstance): string | undefined => {
if (e.getType() === 'mention') {
return `@${e.getData().mention.id}`
}
return undefined
}
stateToMarkdown(editorState.getCurrentContent(), { renderEntity: renderMentionMarkdown })