From 73f36e7ec60138e0c62f6240a61591b2c96a7e3e Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Wed, 6 Dec 2023 19:57:39 -0500 Subject: [PATCH] fix(utils): Markdown link replacement with <> but no spaces --- .../src/__tests__/__snapshots__/markdownLinks.test.ts.snap | 1 + packages/docusaurus-utils/src/__tests__/markdownLinks.test.ts | 1 + packages/docusaurus-utils/src/markdownLinks.ts | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) 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 7c5fc874287c..3c4f732a82fd 100644 --- a/packages/docusaurus-utils/src/__tests__/__snapshots__/markdownLinks.test.ts.snap +++ b/packages/docusaurus-utils/src/__tests__/__snapshots__/markdownLinks.test.ts.snap @@ -176,6 +176,7 @@ exports[`replaceMarkdownLinks replaces links with same title as URL 1`] = ` "brokenMarkdownLinks": [], "newContent": " [foo.md](/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 b7d7abd556b5..ce0acfb3a99b 100644 --- a/packages/docusaurus-utils/src/__tests__/markdownLinks.test.ts +++ b/packages/docusaurus-utils/src/__tests__/markdownLinks.test.ts @@ -231,6 +231,7 @@ The following operations are defined for [URI]s: }, fileString: ` [foo.md](foo.md) +[./foo.md](<./foo.md>) [./foo.md](./foo.md) [foo.md](./foo.md) [./foo.md](foo.md) diff --git a/packages/docusaurus-utils/src/markdownLinks.ts b/packages/docusaurus-utils/src/markdownLinks.ts index 88825e502f14..13afca33905e 100644 --- a/packages/docusaurus-utils/src/markdownLinks.ts +++ b/packages/docusaurus-utils/src/markdownLinks.ts @@ -128,7 +128,7 @@ export function replaceMarkdownLinks({ const linkSuffixPattern = '(?:\\?[^#>\\s]+)?(?:#[^>\\s]+)?'; const linkCapture = (forbidden: string) => `((?!https?://|@site/)[^${forbidden}#?]+)`; - const linkURLPattern = `(?:${linkCapture( + const linkURLPattern = `(?:(?!<)${linkCapture( '()\\s', )}${linkSuffixPattern}|<${linkCapture('>')}${linkSuffixPattern}>)`; const linkPattern = new RegExp(