How to use the marked library guys I am not understanding anything and going CRAZY PLEASE HELP

I imported the marked library and now my previewer outputs the html elements how do I change it? I feel like this is too hard so many new things too learn its painful dangerouslyset html this that. I am going crazy.

Hi @ankurchaulagain, take a look at what React has to say about dangerouslySetInnerHTML, they also provide a quick example.

What you want to do then, is to use the html that markedjs is giving you, and apply directly to the DOM.

Which means that you need to follow the example provided in the docs to be something like:

// create the markup with marked
function createMarkup() {
  return {__html: marked(my_markdown_input)};

  // render it in the DOM
  return <div dangerouslySetInnerHTML={createMarkup()} />;

I will let you figure it out how to stitch it together with the code you already have :slight_smile:

Hope this helps :sparkles:

1 Like

Thank you so much my friend!

on the side note do you know how to create that window like object that they have in the solution?

I also had question on this:

My markdown previewer interprets carriage returns and renders them as br (line break) elements.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.