mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-12 00:27:21 +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
|
||||
test('links in HTML comments', () => {
|
||||
expect(
|
||||
|
|
|
@ -67,7 +67,7 @@ export function replaceMarkdownLinks<T extends ContentPaths>({
|
|||
// ink
|
||||
// [doc1]: doc1.md -> we replace this doc1.md with correct link
|
||||
const mdRegex =
|
||||
/(?:(?:\]\()|(?:\]:\s?))(?!https?:\/\/|@site\/)(?<filename>[^'")\]\s>]+\.mdx?)/g;
|
||||
/(?:(?:\]\()|(?:\]:\s*))(?!https?:\/\/|@site\/)(?<filename>[^'")\]\s>]+\.mdx?)/g;
|
||||
let mdMatch = mdRegex.exec(modifiedLine);
|
||||
while (mdMatch !== null) {
|
||||
// Replace it to correct html link.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue