fix(utils): Markdown link replacement with <> but no spaces (#9617)

This commit is contained in:
Joshua Chen 2023-12-07 05:27:28 -05:00 committed by GitHub
parent 8dd1e13f2a
commit c8c93a3854
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 1 deletions

View file

@ -176,6 +176,7 @@ exports[`replaceMarkdownLinks replaces links with same title as URL 1`] = `
"brokenMarkdownLinks": [], "brokenMarkdownLinks": [],
"newContent": " "newContent": "
[foo.md](/docs/foo) [foo.md](/docs/foo)
[./foo.md](</docs/foo>)
[./foo.md](/docs/foo) [./foo.md](/docs/foo)
[foo.md](/docs/foo) [foo.md](/docs/foo)
[./foo.md](/docs/foo) [./foo.md](/docs/foo)

View file

@ -231,6 +231,7 @@ The following operations are defined for [URI]s:
}, },
fileString: ` fileString: `
[foo.md](foo.md) [foo.md](foo.md)
[./foo.md](<./foo.md>)
[./foo.md](./foo.md) [./foo.md](./foo.md)
[foo.md](./foo.md) [foo.md](./foo.md)
[./foo.md](foo.md) [./foo.md](foo.md)

View file

@ -128,7 +128,7 @@ export function replaceMarkdownLinks<T extends ContentPaths>({
const linkSuffixPattern = '(?:\\?[^#>\\s]+)?(?:#[^>\\s]+)?'; const linkSuffixPattern = '(?:\\?[^#>\\s]+)?(?:#[^>\\s]+)?';
const linkCapture = (forbidden: string) => const linkCapture = (forbidden: string) =>
`((?!https?://|@site/)[^${forbidden}#?]+)`; `((?!https?://|@site/)[^${forbidden}#?]+)`;
const linkURLPattern = `(?:${linkCapture( const linkURLPattern = `(?:(?!<)${linkCapture(
'()\\s', '()\\s',
)}${linkSuffixPattern}|<${linkCapture('>')}${linkSuffixPattern}>)`; )}${linkSuffixPattern}|<${linkCapture('>')}${linkSuffixPattern}>)`;
const linkPattern = new RegExp( const linkPattern = new RegExp(