Browse Source

Merge pull request #1196 from ClarenceDan/main

fix: Resolve markdown link issue
Yifei Zhang 1 year ago
parent
commit
435e82c824
1 changed files with 6 additions and 1 deletions
  1. 6 1
      app/components/markdown.tsx

+ 6 - 1
app/components/markdown.tsx

@@ -46,8 +46,13 @@ function _MarkDownContent(props: { content: string }) {
       ]}
       components={{
         pre: PreCode,
+        a: (aProps) => {
+          const href = aProps.href || "";
+          const isInternal = /^\/#/i.test(href);
+          const target = isInternal ? "_self" : aProps.target ?? "_blank";
+          return <a {...aProps} target={target} />;
+        },
       }}
-      linkTarget={"_blank"}
     >
       {props.content}
     </ReactMarkdown>