Hello all. I’m trying to build the Markdown Previewer in React on my computer. But I can’t figure out how to get marked.js into the project? How do you use the marked() function?
I tried putting this in the App.js:
const markedScript = document.createElement("script");
markedScript.src = "https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.6/marked.js";
markedScript.async = true;
I tried installing the marked script with command line. The JSON file:
I also tried putting this line at the bottom of index.html:
I’m trying to access the marked function in App.js:
let outputText = marked(event.target.value);
I’m working on my desktop so I don’t have an online version at the moment. (Side-question; can you put React onto Codepen if there’s several files?)
First variant is completely wrong.
Second variant with installing should work. You just need to import:
import marked from 'marked';
and then you can use it in your code.
Third variant with CDN should also work only you should probably put it in
Side answer: for several files use codesandbox.io
#1 - I’m not even really sure where I got that code from. confused
#2 - Of course, I forgot to import the file! That caused the mishap.
#3 - As long as #2 works there’s no need for this. It was just a desperation attempt.
I’ve never heard of that one but I’ll need to try it! Somebody else told me you can host pages on Github but I’m not sure about React apps.
I found this because I was having the same issue as you with marked.js!
I think I know where you got the mystery code from (because I was using the same)! It is just adapting the code snippet in this stack overflow answer
I did this and I actually think it worked. But importing marked from ‘marked’; is probably simpler and better!
You can definitely host a react project on github pages.
Just wanted to chime in!
Hey Adam, also got stack at the same problem.
you can install marked at your project folder by running the command
npm install --save marked, and don’t forget to import marked from ‘marked’; at your App file.
Got helped by #JacksonBates at this link: Import Marked library into project