Skip to content

Open links in a new window #2982

Answered by UziTech
viharm asked this question in Q&A
Sep 12, 2023 · 2 comments · 5 replies
Discussion options

You must be logged in to vote

Thanks for loving marked! 💖

You can override the link renderer to add whatever attributes you want.

const renderer = {
  link(href, title, text) {
    const link = marked.Renderer.prototype.link.call(this, href, title, text);
    return link.replace("<a","<a target='_blank' rel='noreferrer' ");
  }
};

marked.use({
    renderer
});

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
5 replies
@romatou
Comment options

@UziTech
Comment options

@romatou
Comment options

@UziTech
Comment options

@romatou
Comment options

Answer selected by viharm
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants