mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-15 01:57:28 +02:00
fix(utils): convert Markdown links in reference-style links (#6617)
This commit is contained in:
parent
d2574b287f
commit
74a645e612
2 changed files with 44 additions and 1 deletions
|
@ -62,6 +62,49 @@ describe('replaceMarkdownLinks', () => {
|
||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('reference style Markdown links', () => {
|
||||||
|
expect(
|
||||||
|
replaceMarkdownLinks({
|
||||||
|
siteDir: '.',
|
||||||
|
filePath: 'docs/intro/intro.md',
|
||||||
|
contentPaths: {
|
||||||
|
contentPath: 'docs',
|
||||||
|
contentPathLocalized: 'i18n/docs-localized',
|
||||||
|
},
|
||||||
|
|
||||||
|
sourceToPermalink: {
|
||||||
|
'@site/docs/intro/intro.md': '/docs/intro',
|
||||||
|
'@site/docs/api/classes/divine_uri.URI.md': '/docs/api/classes/uri',
|
||||||
|
},
|
||||||
|
|
||||||
|
fileString: `
|
||||||
|
The following operations are defined for [URI]s:
|
||||||
|
|
||||||
|
* [info]: Returns metadata about the resource,
|
||||||
|
* [list]: Returns metadata about the resource's children (like getting the content of a local directory).
|
||||||
|
|
||||||
|
[URI]: ../api/classes/divine_uri.URI.md
|
||||||
|
[info]: ../api/classes/divine_uri.URI.md#info
|
||||||
|
[list]: ../api/classes/divine_uri.URI.md#list
|
||||||
|
`,
|
||||||
|
}),
|
||||||
|
).toMatchInlineSnapshot(`
|
||||||
|
Object {
|
||||||
|
"brokenMarkdownLinks": Array [],
|
||||||
|
"newContent": "
|
||||||
|
The following operations are defined for [URI]s:
|
||||||
|
|
||||||
|
* [info]: Returns metadata about the resource,
|
||||||
|
* [list]: Returns metadata about the resource's children (like getting the content of a local directory).
|
||||||
|
|
||||||
|
[URI]: /docs/api/classes/uri
|
||||||
|
[info]: /docs/api/classes/uri#info
|
||||||
|
[list]: /docs/api/classes/uri#list
|
||||||
|
",
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
// TODO bad
|
// TODO bad
|
||||||
test('links in HTML comments', () => {
|
test('links in HTML comments', () => {
|
||||||
expect(
|
expect(
|
||||||
|
|
|
@ -67,7 +67,7 @@ export function replaceMarkdownLinks<T extends ContentPaths>({
|
||||||
// ink
|
// ink
|
||||||
// [doc1]: doc1.md -> we replace this doc1.md with correct link
|
// [doc1]: doc1.md -> we replace this doc1.md with correct link
|
||||||
const mdRegex =
|
const mdRegex =
|
||||||
/(?:(?:\]\()|(?:\]:\s?))(?!https?:\/\/|@site\/)(?<filename>[^'")\]\s>]+\.mdx?)/g;
|
/(?:(?:\]\()|(?:\]:\s*))(?!https?:\/\/|@site\/)(?<filename>[^'")\]\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