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: same text and url #68

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 2 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
7 changes: 7 additions & 0 deletions utils/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ export function resolveMarkdownRelativeLinks(
if (path.startsWith("http") || path.startsWith("https")) {
return match;
}
// match a link (e.g. [./example](./example), will replace the link, not the text)
if (url) {
return match.replace(
`(${path})`,
`(${cdnBaseURL}/${path.replace(/^\.\//, "")})`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please double-check if we could fix/improve the regex above? generating new (${path}) seems hacky to replace while haven't tried it locally... Also what is a sample README URL we can test against?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, here some readme where there is the issue: #68 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the regexp to simplify code and avoid too many if.

);
}
return match.replace(path, `${cdnBaseURL}/${path.replace(/^\.\//, "")}`);
},
);
Expand Down