Skip to content

Commit

Permalink
rel="noopener noreferrer"
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacasonato committed Oct 15, 2021
1 parent 3abb973 commit 82db7cb
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ class Renderer extends marked.Renderer {
const html = Prism.highlight(code, grammar, language);
return `<div class="highlight highlight-source-${language}"><pre>${html}</pre></div>`;
}

link(href: string, title: string, text: string) {
if (href.startsWith("#")) {
return `<a href="${href}" title="${title}">${text}</a>`;
}
return `<a href="${href}" title="${title}" rel="noopener noreferrer">${text}</a>`;
}
}

export function render(markdown: string, baseUrl: string | undefined): string {
Expand All @@ -45,7 +52,7 @@ export function render(markdown: string, baseUrl: string | undefined): string {
allowedAttributes: {
...sanitizeHtml.defaults.allowedAttributes,
img: ["src", "alt", "height", "width", "align"],
a: ["id", "aria-hidden", "href", "tabindex"],
a: ["id", "aria-hidden", "href", "tabindex", "rel"],
svg: ["viewbox", "width", "height", "aria-hidden"],
path: ["fill-rule", "d"],
},
Expand Down

0 comments on commit 82db7cb

Please sign in to comment.