mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-13 00:57:53 +02:00
fix(utils): Markdown linkification match local paths beginning with http (#6478)
This commit is contained in:
parent
d6cff8c754
commit
02186a2b20
2 changed files with 5 additions and 1 deletions
|
@ -21,6 +21,7 @@ describe('replaceMarkdownLinks', () => {
|
||||||
'@site/docs/intro.md': '/docs/intro',
|
'@site/docs/intro.md': '/docs/intro',
|
||||||
'@site/docs/foo.md': '/doc/foo',
|
'@site/docs/foo.md': '/doc/foo',
|
||||||
'@site/docs/bar/baz.md': '/doc/baz',
|
'@site/docs/bar/baz.md': '/doc/baz',
|
||||||
|
'@site/docs/http.foo.md': '/doc/http',
|
||||||
},
|
},
|
||||||
fileString: `
|
fileString: `
|
||||||
[foo](./foo.md)
|
[foo](./foo.md)
|
||||||
|
@ -29,6 +30,7 @@ describe('replaceMarkdownLinks', () => {
|
||||||
[http](http://github.com/facebook/docusaurus/README.md)
|
[http](http://github.com/facebook/docusaurus/README.md)
|
||||||
[https](https://github.com/facebook/docusaurus/README.md)
|
[https](https://github.com/facebook/docusaurus/README.md)
|
||||||
[asset](./foo.js)
|
[asset](./foo.js)
|
||||||
|
[looks like http...](http.foo.md)
|
||||||
[nonexistent](hmmm.md)
|
[nonexistent](hmmm.md)
|
||||||
`,
|
`,
|
||||||
}),
|
}),
|
||||||
|
@ -51,6 +53,7 @@ describe('replaceMarkdownLinks', () => {
|
||||||
[http](http://github.com/facebook/docusaurus/README.md)
|
[http](http://github.com/facebook/docusaurus/README.md)
|
||||||
[https](https://github.com/facebook/docusaurus/README.md)
|
[https](https://github.com/facebook/docusaurus/README.md)
|
||||||
[asset](./foo.js)
|
[asset](./foo.js)
|
||||||
|
[looks like http...](/doc/http)
|
||||||
[nonexistent](hmmm.md)
|
[nonexistent](hmmm.md)
|
||||||
",
|
",
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,8 @@ export function replaceMarkdownLinks<T extends ContentPaths>({
|
||||||
// Replace inline-style links or reference-style links e.g:
|
// Replace inline-style links or reference-style links e.g:
|
||||||
// This is [Document 1](doc1.md) -> we replace this doc1.md with correct link
|
// This is [Document 1](doc1.md) -> we replace this doc1.md with correct link
|
||||||
// [doc1]: doc1.md -> we replace this doc1.md with correct link
|
// [doc1]: doc1.md -> we replace this doc1.md with correct link
|
||||||
const mdRegex = /(?:(?:\]\()|(?:\]:\s?))(?!https?)([^'")\]\s>]+\.mdx?)/g;
|
const mdRegex =
|
||||||
|
/(?:(?:\]\()|(?:\]:\s?))(?!https?:\/\/)([^'")\]\s>]+\.mdx?)/g;
|
||||||
let mdMatch = mdRegex.exec(modifiedLine);
|
let mdMatch = mdRegex.exec(modifiedLine);
|
||||||
while (mdMatch !== null) {
|
while (mdMatch !== null) {
|
||||||
// Replace it to correct html link.
|
// Replace it to correct html link.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue