Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[draft-js-export-markdown] Add option for custom entity render function #234

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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