simplemde-markdown-editor icon indicating copy to clipboard operation
simplemde-markdown-editor copied to clipboard

How to render markdown text after saving it in database

Open anuj9196 opened this issue 7 years ago • 8 comments

I'm using this in my application.

This is working fine as data is saving to database with markdown syntax.

Now, I want to render this data on a separate file.

How to render the data on view?

anuj9196 avatar May 30 '17 08:05 anuj9196

this is not an issue of this editor, its your job to find a solution to render md-files - there are many solutions out there.

KOTRET avatar May 31 '17 05:05 KOTRET

I also need to render data, and I don't want to use a separate solution that duplicates exactly what this plugin does, as that both duplicates the code and might not even support the same subset of Markdown that this does. Exposing the rendered text would be a very nice feature.

skorokithakis avatar Jun 15 '17 00:06 skorokithakis

It's up to the back-end framework , for example in django I use markdown before rendering the data, so there will be a way in your language or framework.

Kishy-nivas avatar Jun 17 '17 13:06 Kishy-nivas

My language or framework is vanilla JS. Why should I have to load a second library when I already have one loaded?

skorokithakis avatar Jun 17 '17 13:06 skorokithakis

I don't get all this editor does is append the formatting codes(** ,#, etc ) it's up-to the back-end language to store it as it is and display it with a markdown .

Kishy-nivas avatar Jun 17 '17 14:06 Kishy-nivas

The editor has a built-in markdown renderer, which it uses to display markdown as HTML. We're arguing that that renderer should be exposed so we don't have to load a whole other renderer when there is already one included in SimpleMDE.

For anyone reading this, you can currently use the built-in renderer simply by calling:

simplemde.markdown(simplemde.value)

skorokithakis avatar Jun 17 '17 14:06 skorokithakis

SimpleMDE uses Marked (https://marked.js.org/) as a renderer internally, and already includes that in dependencies. So I see it pretty logical to use that library.

KristobalJunta avatar May 22 '18 21:05 KristobalJunta

To follow on from the post by @KristobalJunta here is the code you need

import * as marked from "marked";
var html = marked(input);

chris-eaton avatar Jul 23 '21 09:07 chris-eaton