Update markdown.tsx

feat: Add option to open links in same window for internal links
This commit is contained in:
Clarence Dan
2023-04-28 11:15:06 +08:00
committed by GitHub
parent 1a0d01e5b0
commit aa1571a83c

View File

@@ -95,13 +95,11 @@ export function Markdown(
]}
components={{
pre: PreCode,
}}
renderers={{
link: (props) => {
const isInternal = /^\/(?!\/)/.test(props.href);
const target = isInternal ? "_self" : "_blank";
return <a {...props} target={target} />;
},
a: (aProps) => {
const isInternal = /^\/#/i.test(aProps.href);
const target = isInternal ? "_self" : aProps.target ?? "_blank";
return <a {...aProps} target={target} />;
},
}}
>
{props.content}