Rosey / markdown-draft-js

A tool to convert content created in DraftJS to markdown and vice versa.
https://rosey.github.io/markdown-draft-js/
MIT License
318 stars 69 forks source link

Provide the code for the remarkableMentionPlugin #116

Open isabellachen opened 4 years ago

isabellachen commented 4 years ago

Hi Rosey,

Thank you for the work on this great plugin. Would it be possible to provide the code to the remarkableMentionPlugin in the docs? I'm trying to create a plugin to convert the htmltag to DraftJS, but I can't figure out how to write the plugin. The remarkable plugin docs are very cryptic.

In your code snippet, where does blockEntities.mention_open come from? Is this something created in your plugin?

What in the world is the item argument passed to the mention_open method?

I know you're very busy, but if you have the time to dump the code for the plugin somewhere, it would be super helpful to understanding how the conversion from markdownToDraft can be extended.

Thank you :)

danielsnider commented 4 years ago

Hi @Rosey,

I have the same issue.

Hi @isabellachen, If you find a way to convert a mention html tag to DraftJS can you please share the code?

I'll let you know if I find a way!!

danielsnider commented 4 years ago

@isabellachen, I may found the code:

...
    var markdown = 'Test @[Rose](1)';
    var conversionResult = markdownToDraft(markdown, {
      remarkablePlugins: [mentionWrapper],
      blockEntities: {
        mention_open: function (item) {
          return {
            type: 'MENTION',
            mutability: 'IMMUTABLE',
            data: {
              id: item.id,
              name: item.name
            }
          };
        }
      }
    });
...

From here: https://github.com/Rosey/markdown-draft-js/blob/master/test/markdown-to-draft.spec.js#L415

danielsnider commented 4 years ago

I opened PR #118 adding a link to the code definition of mentionWrapper.