mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-11 08:07:26 +02:00
fix(utils): fix Markdown link replacement when link text is same as href (#7464)
This commit is contained in:
parent
5207e25291
commit
6e62bba30f
3 changed files with 7 additions and 5 deletions
|
@ -102,10 +102,10 @@ exports[`replaceMarkdownLinks replaces links with same title as URL 1`] = `
|
||||||
{
|
{
|
||||||
"brokenMarkdownLinks": [],
|
"brokenMarkdownLinks": [],
|
||||||
"newContent": "
|
"newContent": "
|
||||||
[/docs/foo](foo.md)
|
|
||||||
[/docs/foo](./foo.md)
|
|
||||||
[foo.md](/docs/foo)
|
[foo.md](/docs/foo)
|
||||||
[.//docs/foo](foo.md)
|
[./foo.md](/docs/foo)
|
||||||
|
[foo.md](/docs/foo)
|
||||||
|
[./foo.md](/docs/foo)
|
||||||
",
|
",
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
|
@ -204,7 +204,6 @@ The following operations are defined for [URI]s:
|
||||||
).toMatchSnapshot();
|
).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
// FIXME
|
|
||||||
it('replaces links with same title as URL', () => {
|
it('replaces links with same title as URL', () => {
|
||||||
expect(
|
expect(
|
||||||
replaceMarkdownLinks({
|
replaceMarkdownLinks({
|
||||||
|
|
|
@ -137,7 +137,10 @@ export function replaceMarkdownLinks<T extends ContentPaths>({
|
||||||
.split('/')
|
.split('/')
|
||||||
.map((part) => part.replace(/\s/g, '%20'))
|
.map((part) => part.replace(/\s/g, '%20'))
|
||||||
.join('/');
|
.join('/');
|
||||||
modifiedLine = modifiedLine.replace(mdLink, encodedPermalink);
|
modifiedLine = modifiedLine.replace(
|
||||||
|
mdMatch[0]!,
|
||||||
|
mdMatch[0]!.replace(mdLink, encodedPermalink),
|
||||||
|
);
|
||||||
// Adjust the lastIndex to avoid passing over the next link if the
|
// Adjust the lastIndex to avoid passing over the next link if the
|
||||||
// newly replaced URL is shorter.
|
// newly replaced URL is shorter.
|
||||||
mdRegex.lastIndex += encodedPermalink.length - mdLink.length;
|
mdRegex.lastIndex += encodedPermalink.length - mdLink.length;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue