Links Rendered by Marked.js Open in New Tab? (Markdown Previewer Project)

Links Rendered by Marked.js Open in New Tab? (Markdown Previewer Project)
0

#1

Hi Coders!

Here’s the (optional) instruction from the Markdown Previewer Project that I’m grappling with:

When I click a link rendered by my markdown previewer, the link is opened up in a new tab (HINT: read the Marked.js docs for this one!).

The main Marked.js doc, their advanced configurations page, and their extensibility page all don’t have anything about “link,” “target,” or “tab” – search terms I used. And in Marked’s demo, when I click on a link, it opens in the same page.

Any advice for getting more out of these docs? Should I be looking out for more subtle clues?

If not, I’ll write my own function to take care of it. :stuck_out_tongue_closed_eyes:

Thanks!
-jan


#2

I think this might be an oversight, and should possibly have been removed from the challenge - see this issue:

Possibly @vipatron knows more about it


#3

Perfect! Thanks Dan. That answers it. That instruction should indeed be removed. Good to know :smile:


#4

It works in the sample site for that challenge.


#5

It seems like this optional instruction has been removed from the test, but in case someone may need this feature: it can be be done by

var renderer = new marked.Renderer();
renderer.link = function(href, title, text) {
    var link = marked.Renderer.prototype.link.call(this, href, title, text);
    return link.replace("<a","<a target='_blank' ");
};
marked.setOptions({
    renderer: renderer
});

See details in marked’s this PR