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} + ‘’;
}
So, this part of code:
renderer.link = function (href, title, text) {
return <a target="_blank" href="${href}">${text} + ‘’;
}
can be understood as :
const renderer = {link: function (href, title, text) {
return <a target="_blank" href="${href}">${text} + ‘’;
}}
so, this part of code:
renderer.link = function (href, title, text) {
return <a target="_blank" href="${href}">${text} + ‘’;
}
is basically updating the value of original “link” property of object renderer? Then why should I write a parameter “title” there?
and for this part :
const renderer = new marked.Renderer();
what does it mean?
Yes, you change link function, I’m sorry, can’t explain mark.js structure in detail, it’s a bit more complicated, there’s tokenizer function (The tokenizer defines how to turn markdown text into tokens.), I might be wrong but I guess if you want to change number or order of arguments you will have to change tokenizer first.
So, Renderer() is a built-in constructor function of mark js. I see. I understand it now. Thank you!!!
Erm. I think I wont go that deep into mark.js for now. Understanding what these two code are for is enough for me. I just take the parameter “title” is a must for the code. Thank You!