File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -105,6 +105,24 @@ describe("ChatMarkdown Windows file links", () => {
105105 } ,
106106 ) ;
107107
108+ it . each ( [ true , false ] ) (
109+ "does not disambiguate the same file in links and inline code with parseRawHtml=%s" ,
110+ ( parseRawHtml ) => {
111+ const path = String . raw `C:\Users\shawn\project\src\main.ts` ;
112+ const html = renderToStaticMarkup (
113+ < ChatMarkdown
114+ cwd = "C:/Users/shawn/project"
115+ text = { `[Source](${ path } ) and \`${ path } \`` }
116+ lineBreaks = { ! parseRawHtml }
117+ parseRawHtml = { parseRawHtml }
118+ /> ,
119+ ) ;
120+
121+ expect ( html . match ( / c h a t - m a r k d o w n - f i l e - l i n k / g) ) . toHaveLength ( 2 ) ;
122+ expect ( html ) . not . toContain ( "main.ts ·" ) ;
123+ } ,
124+ ) ;
125+
108126 it . each ( [ true , false ] ) ( "preserves reference links with parseRawHtml=%s" , ( parseRawHtml ) => {
109127 const html = renderToStaticMarkup (
110128 < ChatMarkdown
Original file line number Diff line number Diff line change @@ -882,14 +882,12 @@ function pathParentSegments(path: string): string[] {
882882function buildFileLinkParentSuffixByPath ( filePaths : ReadonlyArray < string > ) : Map < string , string > {
883883 const groups = new Map < string , Set < string > > ( ) ;
884884 for ( const filePath of filePaths ) {
885- const pathSegments = filePath
886- . replaceAll ( "\\" , "/" )
887- . split ( "/" )
888- . filter ( ( segment ) => segment . length > 0 ) ;
885+ const normalizedPath = filePath . replaceAll ( "\\" , "/" ) ;
886+ const pathSegments = normalizedPath . split ( "/" ) . filter ( ( segment ) => segment . length > 0 ) ;
889887 const basename = pathSegments [ pathSegments . length - 1 ] ;
890888 if ( ! basename ) continue ;
891889 const group = groups . get ( basename ) ?? new Set < string > ( ) ;
892- group . add ( filePath ) ;
890+ group . add ( normalizedPath ) ;
893891 groups . set ( basename , group ) ;
894892 }
895893
@@ -1615,7 +1613,9 @@ function ChatMarkdown({
16151613 copyMarkdown : string ,
16161614 className ?: string ,
16171615 ) => {
1618- const parentSuffix = fileLinkParentSuffixByPath . get ( fileLinkMeta . filePath ) ;
1616+ const parentSuffix = fileLinkParentSuffixByPath . get (
1617+ fileLinkMeta . filePath . replaceAll ( "\\" , "/" ) ,
1618+ ) ;
16191619 const labelParts = [ fileLinkMeta . basename ] ;
16201620 if ( typeof parentSuffix === "string" && parentSuffix . length > 0 ) {
16211621 labelParts . push ( parentSuffix ) ;
You can’t perform that action at this time.
0 commit comments