Skip to content

Commit

Permalink
Add links for files from Community Contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
ericglau committed Nov 18, 2024
1 parent 5e03390 commit e361357
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/ui/src/utils/inject-hyperlinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { version as contractsVersion } from "@openzeppelin/contracts/package.jso

export function injectHyperlinks(code: string) {
// We are modifying HTML, so use HTML escaped chars. The pattern excludes paths that include /../ in the URL.
const importRegex = /"(@openzeppelin\/)(contracts-upgradeable\/|contracts\/)((?:(?!\.\.)[^/]+\/)*?[^/]*?)"/g
const contractsRegex = /"(@openzeppelin\/)(contracts-upgradeable\/|contracts\/)((?:(?!\.\.)[^/]+\/)*?[^/]*?)"/g
const communityContractsRegex = /"(@openzeppelin\/)(community-contracts\/contracts\/)((?:(?!\.\.)[^/]+\/)*?[^/]*?)"/g

return code.replace(importRegex, `&quot;<a class="import-link" href="https://github.com/OpenZeppelin/openzeppelin-$2blob/v${contractsVersion}/contracts/$3" target="_blank" rel="noopener noreferrer">$1$2$3</a>&quot;`);
return code.
replace(contractsRegex, `&quot;<a class="import-link" href="https://github.com/OpenZeppelin/openzeppelin-$2blob/v${contractsVersion}/contracts/$3" target="_blank" rel="noopener noreferrer">$1$2$3</a>&quot;`).
replace(communityContractsRegex, `&quot;<a class="import-link" href="https://github.com/OpenZeppelin/openzeppelin-community-contracts/blob/master/contracts/$3" target="_blank" rel="noopener noreferrer">$1$2$3</a>&quot;`);
}

0 comments on commit e361357

Please sign in to comment.