Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(utils): fix Markdown link replacement when link text is same as href #7464

Merged
merged 1 commit into from
May 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ exports[`replaceMarkdownLinks replaces links with same title as URL 1`] = `
{
"brokenMarkdownLinks": [],
"newContent": "
[/docs/foo](foo.md)
[/docs/foo](./foo.md)
[foo.md](/docs/foo)
[.//docs/foo](foo.md)
[./foo.md](/docs/foo)
[foo.md](/docs/foo)
[./foo.md](/docs/foo)
",
}
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ The following operations are defined for [URI]s:
).toMatchSnapshot();
});

// FIXME
it('replaces links with same title as URL', () => {
expect(
replaceMarkdownLinks({
Expand Down
5 changes: 4 additions & 1 deletion packages/docusaurus-utils/src/markdownLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ export function replaceMarkdownLinks<T extends ContentPaths>({
.split('/')
.map((part) => part.replace(/\s/g, '%20'))
.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
// newly replaced URL is shorter.
mdRegex.lastIndex += encodedPermalink.length - mdLink.length;
Expand Down