@@ -15,6 +15,7 @@ import type { MDXComponents } from "mdx/types";
1515import muiComponents from "mui-mdx-components" ;
1616import * as React from "react" ;
1717import * as runtime from "react/jsx-runtime" ;
18+ import { Link } from "react-router-dom" ;
1819import remarkGfm from "remark-gfm" ;
1920import * as R from "remeda" ;
2021
@@ -46,6 +47,16 @@ const REGISTERED_KEYWORDS = [
4647 "}" ,
4748] ;
4849
50+ const EXTERNAL_PROTOCOLS = [ "http://" , "https://" , "mailto:" , "tel:" ] ;
51+
52+ const LinkHandler : React . FC < { href : string } > = ( { href, ...props } ) => {
53+ // If the href starts with "http" or "https", it's an external link
54+ if ( EXTERNAL_PROTOCOLS . some ( ( protocol ) => href . startsWith ( protocol ) ) )
55+ return < a href = { href } target = "_blank" rel = "noopener noreferrer" { ...props } /> ;
56+
57+ return < Link to = { href } { ...props } /> ;
58+ } ;
59+
4960const CustomMDXComponents : MDXComponents = {
5061 h1 : ( props ) => < h1 style = { { margin : 0 } } { ...props } /> ,
5162 h2 : ( props ) => < h2 style = { { margin : 0 } } { ...props } /> ,
@@ -54,6 +65,7 @@ const CustomMDXComponents: MDXComponents = {
5465 h5 : ( props ) => < h5 style = { { margin : 0 } } { ...props } /> ,
5566 h6 : ( props ) => < h6 style = { { margin : 0 } } { ...props } /> ,
5667 strong : ( props ) => < strong { ...props } /> ,
68+ a : ( props ) => < LinkHandler { ...props } /> ,
5769 hr : ( props ) => < StyledDivider { ...props } /> ,
5870 img : ( props ) => < img style = { { maxWidth : "100%" } } alt = "" { ...props } /> ,
5971 em : ( props ) => < em { ...props } /> ,
0 commit comments