Skip to content

Commit ff286cb

Browse files
fix: remove repoOwner so it works across forks
1 parent 854b78e commit ff286cb

2 files changed

Lines changed: 4 additions & 6 deletions

File tree

src/common/utils.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,29 +1057,28 @@ export function extractCodeReferenceLinkMetadata(anchor: Element): CodeReference
10571057
* Process GitHub blob permalinks in HTML and add data attributes for local file handling.
10581058
* Finds blob permalinks (e.g., /blob/[sha]/file.ts#L10), checks if files exist locally,
10591059
* and adds data attributes to enable clicking to open local files.
1060+
* Supports links from any repository owner to work across forks.
10601061
*
10611062
* @param bodyHTML - The HTML content to process
1062-
* @param repoOwner - GitHub repository owner
10631063
* @param repoName - GitHub repository name
10641064
* @param authority - Git protocol URL authority (e.g., 'github.com')
10651065
* @param fileExistsCheck - Async function that checks if a file exists locally given its relative path
10661066
* @returns Promise resolving to processed HTML
10671067
*/
10681068
export async function processPermalinks(
10691069
bodyHTML: string,
1070-
repoOwner: string,
10711070
repoName: string,
10721071
authority: string,
10731072
fileExistsCheck: (filePath: string) => Promise<boolean>
10741073
): Promise<string> {
10751074
try {
10761075
const escapedRepoName = escapeRegExp(repoName);
1077-
const escapedRepoOwner = escapeRegExp(repoOwner);
10781076
const escapedAuthority = escapeRegExp(authority);
10791077

10801078
// Process blob permalinks (exclude already processed links)
1079+
// Allow any owner to support links across forks
10811080
const blobPattern = new RegExp(
1082-
`<a\\s+(?![^>]*data-permalink-processed)([^>]*?href="https?:\/\/${escapedAuthority}\/${escapedRepoOwner}\/${escapedRepoName}\/blob\/[0-9a-f]{40}\/(?<filePath>[^"#]+)#L(?<startLine>\\d+)(?:-L(?<endLine>\\d+))?"[^>]*?)>(?<linkText>[^<]*?)<\/a>`,
1081+
`<a\\s+(?![^>]*data-permalink-processed)([^>]*?href="https?:\/\/${escapedAuthority}\/[^\/]+\/${escapedRepoName}\/blob\/[0-9a-f]{40}\/(?<filePath>[^"#]+)#L(?<startLine>\\d+)(?:-L(?<endLine>\\d+))?"[^>]*?)>(?<linkText>[^<]*?)<\/a>`,
10831082
'g'
10841083
);
10851084

src/github/utils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,6 @@ export async function processPermalinks(
346346
): Promise<string> {
347347
try {
348348
const repoName = githubRepository.remote.repositoryName;
349-
const repoOwner = githubRepository.remote.owner;
350349
const authority = githubRepository.remote.gitProtocol.url.authority;
351350

352351
// Create file existence check callback
@@ -360,7 +359,7 @@ export async function processPermalinks(
360359
}
361360
};
362361

363-
return await processPermalinksCore(bodyHTML, repoOwner, repoName, authority, fileExistsCheck);
362+
return await processPermalinksCore(bodyHTML, repoName, authority, fileExistsCheck);
364363
} catch (error) {
365364
Logger.error(`Failed to process blob permalinks in HTML: ${error}`, 'processPermalinks');
366365
return bodyHTML;

0 commit comments

Comments
 (0)