11import { describe , expect , it } from "vite-plus/test" ;
2+ import { createElement } from "react" ;
3+ import { renderToStaticMarkup } from "react-dom/server" ;
4+ import ReactMarkdown from "react-markdown" ;
25
36import {
47 extractMarkdownLinkHrefs ,
@@ -9,6 +12,25 @@ import {
912 shouldOpenMarkdownFileLinkInEditor ,
1013} from "./markdown-links" ;
1114
15+ function renderMarkdownLinkHref ( markdown : string ) : string | undefined {
16+ let renderedHref : string | undefined ;
17+ renderToStaticMarkup (
18+ createElement (
19+ ReactMarkdown ,
20+ {
21+ components : {
22+ a ( { href } ) {
23+ renderedHref = href ;
24+ return createElement ( "a" , { href } ) ;
25+ } ,
26+ } ,
27+ } ,
28+ markdown ,
29+ ) ,
30+ ) ;
31+ return renderedHref ;
32+ }
33+
1234describe ( "extractMarkdownLinkHrefs" , ( ) => {
1335 it ( "extracts angle-bracketed paths containing spaces" , ( ) => {
1436 expect (
@@ -141,6 +163,17 @@ describe("resolveMarkdownFileLinkTarget", () => {
141163 } ) ;
142164 } ) ;
143165
166+ it ( "resolves relative spaced folders from the markdown renderer" , ( ) => {
167+ const href = renderMarkdownLinkHref ( "[folder](<docs/My Folder>)" ) ;
168+
169+ expect ( href ) . toBe ( "docs/My%20Folder" ) ;
170+ expect ( resolveMarkdownFileLinkMeta ( href , "/repo/project" ) ) . toMatchObject ( {
171+ targetPath : "/repo/project/docs/My Folder" ,
172+ workspaceRelativePath : "docs/My Folder" ,
173+ basename : "My Folder" ,
174+ } ) ;
175+ } ) ;
176+
144177 it ( "formats tooltip display paths relative to the cwd for slash-prefixed windows paths" , ( ) => {
145178 expect (
146179 resolveMarkdownFileLinkMeta (
0 commit comments