Hi everyone,
I’ve already done the weather, twitch, and quote projects, so I’m familiar with fetching data from an external website and using JSON.parse() to turn it into a JavaScript object.
However, the following question, from the Markdown Previewer project, seems different to me, and has me stumped:
Instruction from project: When I enter GitHub flavored markdown into the #editor element, the text is rendered as HTML in the #preview element as I type (HINT: You don’t need to parse Markdown yourself - you can import the Marked library for this: https://cdnjs.com/libraries/marked).
- That link has dozens of options of how to access the library. I don’t know which one to choose.
Here are just a few of their many options:
-
marked.js
-
marked.min.js
-
marked.min.js.map (this one seems right, because I’ll probably map the user input using functions from this library, but that’s just a guess …)
- Once I have chosen one of these libraries above, how do I best load it into my project?
How I'm loading it so far, with AJAX
-
I’ve been able to successfully load marked.js into my project with an AJAX request, and then display the entire library (lots of code like
Hacky. if (~item.indexOf('\n '))
). -
Is there something better than this AJAX method I used:
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML =
this.responseText;
}
};
xhttp.open("GET", "https://cdnjs.cloudflare.com/ajax/libs/marked/0.4.0/marked.js", true);
xhttp.send();
}
- Perhaps the most important question… how do I use this library once I’ve loaded it, to parse the input.
Any advice, lesson links, or article links would be appreciated! For any of these questions…
Sorry if the answer is hidden in plain sight…just haven’t been able to find it so far…
Thanks!
Jan