Rosey/markdown-draft-js

[Help] Custom Markdown Syntax - How to handle custom block rules and convert them into an atomic block with entity data?

Closed this issue · 1 comments

I am working in a project that has quite a few custom markdown syntax, i've been given the task to create a rich text editor for it, and have been trying to figure out how to convert the markdown to draft while handling this custom syntax.

I've written a remarkable plugin that handles for example an opening warning tag:

<warning>
## Warning title
This is an **important** warning!
</warning>

This plugin uses a block rule which according to the remarkable documentation made sense.

By digging into the markdown-to-draft.js implementation I noticed that only inline item types from the remarkable parsedData handle block entities.

I've also tried implementing this using the blockTypes to no avail.

My question is, how to handle custom block rules and convert them into an atomic block with entity data?

After further digging I understand that it's preferable to use block level metadata instead of entities..

I've ended up being able to what I needed by hacking into the markdownToDraft function, not proud of my code but it works.

Here's the sandbox with some custom syntax and proper markdownToDraft and draftToMarkdown conversions: https://codesandbox.io/s/gifted-dan-vu4yu.