@@ -6,8 +6,14 @@ import { useMemo } from 'react';
66import type { ReactElement } from 'react' ;
77import Code from './Code' ;
88import { kebabCase } from 'change-case' ;
9+ import { resolveMarkdownLink } from '../lib/markdownLinks' ;
910
10- export default function Markdown ( { content } : { content : string } ) {
11+ interface MarkdownProps {
12+ content : string ;
13+ sourcePath : string ;
14+ }
15+
16+ export default function Markdown ( { content, sourcePath } : MarkdownProps ) {
1117 const processedContent = useMemo ( ( ) => {
1218 // Split content by H2 headings to group sections
1319 const sections = content . split ( / ^ # # / gm) ;
@@ -22,7 +28,7 @@ export default function Markdown({ content }: { content: string }) {
2228 < div key = { `intro-${ index } ` } className = "mb-8" >
2329 < ReactMarkdown
2430 remarkPlugins = { [ remarkGfm ] }
25- components = { getMarkdownComponents ( ) }
31+ components = { getMarkdownComponents ( sourcePath ) }
2632 >
2733 { section }
2834 </ ReactMarkdown >
@@ -42,7 +48,7 @@ export default function Markdown({ content }: { content: string }) {
4248 </ h2 >
4349 < ReactMarkdown
4450 remarkPlugins = { [ remarkGfm ] }
45- components = { getMarkdownComponents ( ) }
51+ components = { getMarkdownComponents ( sourcePath ) }
4652 >
4753 { sectionContent }
4854 </ ReactMarkdown >
@@ -52,12 +58,12 @@ export default function Markdown({ content }: { content: string }) {
5258 } ) ;
5359
5460 return elements ;
55- } , [ content ] ) ;
61+ } , [ content , sourcePath ] ) ;
5662
5763 return < div className = "space-y-8" > { processedContent } </ div > ;
5864}
5965
60- function getMarkdownComponents ( ) {
66+ function getMarkdownComponents ( sourcePath : string ) {
6167 return {
6268 // H1 headings (main page title from Markdown content)
6369 h1 : ( { children, ...props } : any ) => (
@@ -247,10 +253,11 @@ function getMarkdownComponents() {
247253 // Links: only external links open in a new tab; internal links (/docs/...,
248254 // /samples, #anchors) navigate in place
249255 a : ( { children, href, ...props } : any ) => {
250- const isExternal = / ^ h t t p s ? : \/ \/ / i. test ( href ?? '' ) ;
256+ const resolvedHref = resolveMarkdownLink ( href , sourcePath ) ;
257+ const isExternal = / ^ h t t p s ? : \/ \/ / i. test ( resolvedHref ?? '' ) ;
251258 return (
252259 < a
253- href = { href }
260+ href = { resolvedHref }
254261 className = "text-blue-400 hover:text-blue-300 transition-colors"
255262 { ...( isExternal ? { target : '_blank' , rel : 'noopener noreferrer' } : { } ) }
256263 { ...props }
0 commit comments