Skip to content

Commit

Permalink
Open absolute URLs in a new tab
Browse files Browse the repository at this point in the history
  • Loading branch information
haxiomic committed Dec 5, 2023
1 parent a976a97 commit f39bdd3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,13 @@ function App() {
let match = href.match(pattern);
href = '#' + match![1];
}
return <a {...rest} href={href} />
let isAbsolute = /^https?:\/\//.test(href ?? '');
if (isAbsolute) {
// open in new tab
return <a {...rest} href={href} target='_blank' rel='noopener noreferrer' />
} else {
return <a {...rest} href={href} />
}
}
}}
>{readme}</Markdown>
Expand Down

0 comments on commit f39bdd3

Please sign in to comment.