uiwjs / react-md-editor

A simple markdown editor with preview, implemented with React.js and TypeScript.
https://uiwjs.github.io/react-md-editor
MIT License
2.03k stars 149 forks source link

Markdown content from Preview #599

Open SundaramMaheshkumar opened 7 months ago

SundaramMaheshkumar commented 7 months ago

Hi,

In my application, I am using markdown editor along with preview to create a markdown template which gets stored in the backend. This is fine.

In another part of my application, I just show the template content as preview where the editor and tool bar are hidden like below:

image

Now the users can check/uncheck the checkboxes or input some values in those text boxes which is fine.

image

But how do I get these updated changes done in the preview as raw markdown for me store in the backend?

Any help would be appreciated. Thank you!

jaywcjlove commented 7 months ago

@SundaramMaheshkumar You can define your own md syntax, such as <!--input:value=xxxx--!>

Define your own rehype plug-in to parse your grammar

SundaramMaheshkumar commented 7 months ago

@jaywcjlove

I am not sure whether I understand you properly.

Please find my codesandbox here.

In there, I have a button called Get content after the preview. Ideally, I want to get the updated raw markdown content ( as there would be changes when users input in HTML text boxes or checkboxes) on onClick of that button.

Currently, in that sandbox, I did a crude way of getting the raw HTML from the preview. But if I could get the markdown instead of processing the HTML, it would be great. But I couldn't figure out, how to achieve that!!!

Thanks.

SundaramMaheshkumar commented 7 months ago

@jaywcjlove

Any suggestion or idea of how to achieve the above? Thank you

jaywcjlove commented 7 months ago

Do you want to change the content, and then want to get the changed markdown content? @jaywcjlove

SundaramMaheshkumar commented 7 months ago

@jaywcjlove

I am not sure whether I understand you properly.

Please find my codesandbox here.

In there, I have a button called Get content after the preview. Ideally, I want to get the updated raw markdown content ( as there would be changes when users input in HTML text boxes or checkboxes) on onClick of that button.

Currently, in that sandbox, I did a crude way of getting the raw HTML from the preview. But if I could get the markdown instead of processing the HTML, it would be great. But I couldn't figure out, how to achieve that!!!

Thanks.

@jaywcjlove

As you see above images and in the sandbox, I type values in HTML text boxes or checkboxes in the preview. Yes, I wanted to get the markdown with these changes. In the sandbox, I did a crude way of getting the HTML and but am not sure how to get the changes in md format itself.

jaywcjlove commented 7 months ago

@SundaramMaheshkumar Storing it in HTML comments or HTML attributes might be a good idea, but you'll need to change the markdown content yourself.

SundaramMaheshkumar commented 7 months ago

@jaywcjlove

Thanks. I'll just use the HTML as the library supports pure HTML too. Because updating HTML and then updating markdown manually seems redundant.