Skip to content

Conversation

@PierreGUI
Copy link

@PierreGUI PierreGUI commented Mar 16, 2021

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 })

@PierreGUI PierreGUI changed the title Add option for custom entity render function [draft-js-export-markdown] Add option for custom entity render function Mar 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant