diff --git a/packages/docusaurus-utils/src/__tests__/__snapshots__/markdownLinks.test.ts.snap b/packages/docusaurus-utils/src/__tests__/__snapshots__/markdownLinks.test.ts.snap index 1ff0a5351c06..f42727544ff0 100644 --- a/packages/docusaurus-utils/src/__tests__/__snapshots__/markdownLinks.test.ts.snap +++ b/packages/docusaurus-utils/src/__tests__/__snapshots__/markdownLinks.test.ts.snap @@ -102,10 +102,10 @@ exports[`replaceMarkdownLinks replaces links with same title as URL 1`] = ` { "brokenMarkdownLinks": [], "newContent": " -[/docs/foo](foo.md) -[/docs/foo](./foo.md) [foo.md](/docs/foo) -[.//docs/foo](foo.md) +[./foo.md](/docs/foo) +[foo.md](/docs/foo) +[./foo.md](/docs/foo) ", } `; diff --git a/packages/docusaurus-utils/src/__tests__/markdownLinks.test.ts b/packages/docusaurus-utils/src/__tests__/markdownLinks.test.ts index 866e3594d47a..46df9f1e6629 100644 --- a/packages/docusaurus-utils/src/__tests__/markdownLinks.test.ts +++ b/packages/docusaurus-utils/src/__tests__/markdownLinks.test.ts @@ -204,7 +204,6 @@ The following operations are defined for [URI]s: ).toMatchSnapshot(); }); - // FIXME it('replaces links with same title as URL', () => { expect( replaceMarkdownLinks({ diff --git a/packages/docusaurus-utils/src/markdownLinks.ts b/packages/docusaurus-utils/src/markdownLinks.ts index c83bffeb406c..af322fe840d2 100644 --- a/packages/docusaurus-utils/src/markdownLinks.ts +++ b/packages/docusaurus-utils/src/markdownLinks.ts @@ -137,7 +137,10 @@ export function replaceMarkdownLinks({ .split('/') .map((part) => part.replace(/\s/g, '%20')) .join('/'); - modifiedLine = modifiedLine.replace(mdLink, encodedPermalink); + modifiedLine = modifiedLine.replace( + mdMatch[0]!, + mdMatch[0]!.replace(mdLink, encodedPermalink), + ); // Adjust the lastIndex to avoid passing over the next link if the // newly replaced URL is shorter. mdRegex.lastIndex += encodedPermalink.length - mdLink.length;