Skip to content

Commit

Permalink
render all links with target="_blank"
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecarenzo committed Sep 18, 2024
1 parent 7f3f4d0 commit d21bf06
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion scripts/build-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@ function processMarkdownText(source, references = []) {
return `<sup>[[${index}]](${url})</sup>`
});
// Convert to HTML
return marked.parse(source);
const renderer = new marked.Renderer();
const renderLink = renderer.link;
renderer.link = (href, title, text) => {
const html = renderLink.call(renderer, href, title, text);
// Render all links with target="_blank"
return html.replace(/^<a/, `<a target="_blank" rel="noreferrer noopener nofollow"`)
}
return marked(source, { renderer });
}

/**
Expand Down

0 comments on commit d21bf06

Please sign in to comment.