Skip to content

Latest commit

 

History

History
55 lines (44 loc) · 2.25 KB

linkify-code.tsx

File metadata and controls

55 lines (44 loc) · 2.25 KB
 
May 7, 2020
May 7, 2020
1
import * as pageDetect from 'github-url-detection';
Jun 14, 2026
Jun 14, 2026
2
import {$, $$optional} from 'select-dom';
May 8, 2020
May 8, 2020
3
Sep 20, 2022
Sep 20, 2022
4
import features from '../feature-manager.js';
Aug 29, 2024
Aug 29, 2024
5
import {codeElementsSelector, linkifiedUrlClass, linkifyIssues, linkifyUrls} from '../github-helpers/dom-formatters.js';
Mar 23, 2022
Mar 23, 2022
6
import {getRepo} from '../github-helpers/index.js';
Sep 25, 2022
Sep 25, 2022
7
import observe from '../helpers/selector-observer.js';
Feb 3, 2026
Feb 3, 2026
9
function linkifyContent(wrapper: HTMLElement): void {
Nov 1, 2023
Nov 1, 2023
10
// Mark code block as touched to avoid `shorten-links` from acting on these new links in code
Mar 29, 2026
Mar 29, 2026
11
wrapper.classList.add(linkifiedUrlClass);
Nov 1, 2023
Nov 1, 2023
12
Mar 29, 2026
Mar 29, 2026
13
linkifyUrls(wrapper);
Jun 6, 2022
Jun 6, 2022
14
Nov 1, 2023
Nov 1, 2023
15
const currentRepo = pageDetect.isGlobalSearchResults()
16
// Look for the link on the line number
Jun 14, 2026
Jun 14, 2026
17
? getRepo($('.blob-num a', wrapper.parentElement!).href)
Nov 1, 2023
Nov 1, 2023
18
: getRepo();
19
// Some non-repo pages like gists have issue references #3844
20
// They make no sense, but we still want `linkifyURLs` to run there
21
if (!currentRepo) {
22
return;
Jun 6, 2022
Jun 6, 2022
23
}
Apr 25, 2026
Apr 25, 2026
25
// $$optional because the content might not have any comments
26
for (const element of $$optional('.pl-c', wrapper)) {
Nov 1, 2023
Nov 1, 2023
27
linkifyIssues(currentRepo, element);
28
}
Jun 6, 2022
Jun 6, 2022
29
}
Sep 25, 2022
Sep 25, 2022
31
function init(signal: AbortSignal): void {
32
observe(codeElementsSelector, linkifyContent, {signal});
Nov 9, 2021
Nov 9, 2021
35
void features.add(import.meta.url, {
Jul 7, 2021
Jul 7, 2021
37
pageDetect.hasCode,
May 29, 2022
May 29, 2022
39
init,
Aug 19, 2022
Aug 19, 2022
41
42
/*
43
44
## Test URLs
45
Oct 30, 2024
Oct 30, 2024
46
- URLs/issues in comments: https://github.com/refined-github/sandbox/pull/98
47
- URLs in PR files: https://github.com/refined-github/refined-github/pull/546/files#diff-7296d5f600098588b0af5ec9c84486593be79164f97406a0fc3c4ef5211ab2f9
Jul 31, 2026
Jul 31, 2026
48
- URLs in regular files: https://github.com/refined-github/refined-github/blob/3f5fc489e417d4f4a14da5ea423775e9ca9246fd/source/features/copy-markdown.js#L45 (broken: #6336)
49
- Issue reference in file: https://github.com/refined-github/refined-github/blob/2ade9a84b1894c7879fab9d3e2d045e876f941a6/source/features/sort-issues-by-update-time.tsx#L18 (broken: #6336)
Aug 23, 2023
Aug 23, 2023
50
- Code Search: https://github.com/search?q=repo%3AKatsuteDev%2FBackground+marketplace&type=code
Nov 1, 2023
Nov 1, 2023
51
- Code Search: https://github.com/search?q=%2F%23%5Cd%7B4%2C%7D%2F+language%3Atypescript&type=code
Oct 30, 2024
Oct 30, 2024
52
- Code Search that might break: https://github.com/search?q=path%3A.npmrc&type=code
Oct 27, 2024
Oct 27, 2024
53
- Clipped URL that shouldn't be linkified: https://github.com/sindresorhus/linkify-urls/pull/40#pullrequestreview-1593302757
Aug 19, 2022
Aug 19, 2022
54
55
*/