Update markdown.tsx

add _self target for settings
This commit is contained in:
Clarence Dan
2023-04-28 10:40:10 +08:00
committed by GitHub
parent 6419ce345f
commit 14c2135404

View File

@@ -96,7 +96,17 @@ export function Markdown(
components={{
pre: PreCode,
}}
linkTarget={"_blank"}
renderers={{
link: (props) => {
// 判断链接是否为内部地址
const isInternal = /^\/(?!\/)/.test(props.href);
// 如果是内部地址使用_self否则使用_blank
const target = isInternal ? "_self" : "_blank";
return <a {...props} target={target} />;
},
}}
>
{props.content}
</ReactMarkdown>