Tell us what’s happening:
Hi, it’s me again. Could someone explain to me the rationale behind these two code?
I understand that the first one is to overwrite the link method, so that now the link will be opened in a new tab, but how does the code work?
And for the second one, I don’t quite understand this part ({ renderer: renderer }). I roughly know that this is to embed the new written link function to the marked method.
I tried reading the markdown documentation, but could barely understand this part. ORZ
Your code so far
const renderer = new marked.Renderer();
renderer.link = function (href, title, text) {
return <a target="_blank" href="${href}">${text}
+ ‘’;
}
<div id='preview' dangerouslySetInnerHTML={{__html: marked(props.markdown, { renderer: renderer })}} />
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
.
Challenge: Build a Markdown Previewer
Link to the challenge: