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={{ components={{
pre: PreCode, pre: PreCode,
}} a: (aProps) => {
renderers={{ const isInternal = /^\/#/i.test(aProps.href);
link: (props) => { const target = isInternal ? "_self" : aProps.target ?? "_blank";
const isInternal = /^\/(?!\/)/.test(props.href); return <a {...aProps} target={target} />;
const target = isInternal ? "_self" : "_blank"; },
return <a {...props} target={target} />;
},
}} }}
> >
{props.content} {props.content}