I started off in React. I figured that I could use marked in combination with useState and a onChange event. It didn’t work and kept giving me errors. The console did log my keydowns since the error would go +1 with every keydown. I’ve tried npm-install inside of the project and the CDN link. Everything was properly imported inside of the designated JS file that I wanted to use marked with.
Error:
export 'default' (imported as 'marked') was not found in 'marked' (possible exports: Lexer, Parser, Renderer, Slugger, TextRenderer, Tokenizer, defaults, getDefaults, lexer, marked, options, parse, parseInline, parser, setOptions, use, walkTokens)
I went ahead and took a look at the freeCodeCamp rocks example in the dev console, just to get a slight hint on how to stop getting all of these errors. I couldn’t find any hints in there or at least anything that could point me in the right direction. I checked the official documentation of marked.
Except for this piece of code, I was unable to find anything in the ‘get started section’:
<script>
document.getElementById('content').innerHTML =
marked.parse('# Marked in the browser\n\nRendered by **marked**.');
</script>
I went ahead and started a new Vanilla HTML/CSS/JS project to test if it would work there. I’ve assigned a textarea to the editor and a disabled textarea to the preview at first. Later I reassigned a div to the preview to test if that would be of any difference. It was not.
I tried this since it was my most educated guess looking at the example code in the ‘get started section’. Since I don’t know what parse does, and it wasn’t really explained I thought this would do something. It didn’t.
let editor = document.getElementById("editor");
document.getElementById('preview').innerHTML =
marked.parse(editor.innerHTML);
I tried this:
editor.addEventListener('input', function() {
preview.innerHTML = marked(editor.value);
});
Also didn’t work. Then I started experimenting with the placement of the script tags. That didn’t make a difference. I keep getting these errors, but since I do not know how to properly use Marked, which is required for the exam, I don’t know how to resolve this specifically with marked.
Uncaught TypeError: marked is not a function
at HTMLTextAreaElement.<anonymous>
Lastly, I went to the marked demo page, but the part that shows the output is embedded in a iframe element. Except for external scripts I couldn’t find anything that could hint me on how marked works and how I can properly attach it to my page.
I just need a small hint on how to properly attach the script in a workable state. From there I’ll be able to pass all of the other requirements.