summaryrefslogtreecommitdiff
path: root/source/features/linkify-code.tsx
diff options
context:
space:
mode:
authorGravatar Katsute <58778985+Katsute@users.noreply.github.com> 2023-11-01 12:50:07 -0400
committerGravatar GitHub <noreply@github.com> 2023-11-01 16:50:07 +0000
commit99870230d853498feb1be39b7a9df6f7526c5a74 (patch)
treec1bf069ce00ddd34a1a4fa23e0a87f425f3c7baa /source/features/linkify-code.tsx
parentae6ca57b45b4e4ad201793b8dc7f3535c43de976 (diff)
downloadrefined-github-99870230d853498feb1be39b7a9df6f7526c5a74.tar.gz
refined-github-99870230d853498feb1be39b7a9df6f7526c5a74.tar.zst
refined-github-99870230d853498feb1be39b7a9df6f7526c5a74.zip
`linkify-code` - Fix issue links on global search pages (#7005)
Diffstat (limited to '')
-rw-r--r--source/features/linkify-code.tsx24
1 files changed, 15 insertions, 9 deletions
diff --git a/source/features/linkify-code.tsx b/source/features/linkify-code.tsx
index d272e906..ce19fab6 100644
--- a/source/features/linkify-code.tsx
+++ b/source/features/linkify-code.tsx
@@ -20,23 +20,28 @@ function initTitle(signal: AbortSignal): void {
}
function linkifyContent(wrapper: Element): void {
+ // Mark code block as touched to avoid `shorten-links` from acting on these new links in code
+ wrapper.classList.add(linkifiedURLClass);
+
const errors = linkifyURLs(wrapper);
if (errors) {
features.log.error(import.meta.url, 'Links already exist');
console.log(errors);
}
- // Linkify issue refs in comments, exclude gists:
- // https://github.com/refined-github/refined-github/pull/3844#issuecomment-751427568
- if (!pageDetect.isGist()) {
- const currentRepo = getRepo() ?? {};
- for (const element of $$('.pl-c', wrapper)) {
- linkifyIssues(currentRepo, element);
- }
+ const currentRepo = pageDetect.isGlobalSearchResults()
+ // Look for the link on the line number
+ ? getRepo(wrapper.parentElement!.querySelector('.blob-num a')!.href)
+ : getRepo();
+ // Some non-repo pages like gists have issue references #3844
+ // They make no sense, but we still want `linkifyURLs` to run there
+ if (!currentRepo) {
+ return;
}
- // Mark code block as touched to avoid `shorten-links` from acting on these new links in code
- wrapper.classList.add(linkifiedURLClass);
+ for (const element of $$('.pl-c', wrapper)) {
+ linkifyIssues(currentRepo, element);
+ }
}
function init(signal: AbortSignal): void {
@@ -63,6 +68,7 @@ void features.add(import.meta.url, {
- Discussions: https://github.com/File-New-Project/EarTrumpet/discussions/877
- Code Search: https://github.com/search?q=repo%3AKatsuteDev%2FBackground+marketplace&type=code
+- Code Search: https://github.com/search?q=%2F%23%5Cd%7B4%2C%7D%2F+language%3Atypescript&type=code
- Comment: https://github.com/sindresorhus/linkify-urls/pull/40#pullrequestreview-1593302757
*/