|
| 1 | +/* global document */ |
| 2 | +/* eslint-disable unicorn/better-regex */ |
1 | 3 | import reservedNames from 'github-reserved-names/reserved-names.json' with { type: 'json' }; |
2 | 4 |
|
3 | 5 | const patchDiffRegex = /[.](patch|diff)$/; |
@@ -72,6 +74,7 @@ function joinValues(array, delimiter = '/') { |
72 | 74 | * @param href {string} |
73 | 75 | * @param currentUrl {string} |
74 | 76 | */ |
| 77 | +/* eslint-disable complexity */ |
75 | 78 | function shortenRepoUrl(href, currentUrl = 'https://github.com') { |
76 | 79 | if (!href) { |
77 | 80 | return; |
@@ -275,6 +278,7 @@ function shortenRepoUrl(href, currentUrl = 'https://github.com') { |
275 | 278 | // Drop leading and trailing slash of relative path |
276 | 279 | return pathname.replaceAll(/^[/]|[/]$/g, '') + url.search + hash + query; |
277 | 280 | } |
| 281 | +/* eslint-enable complexity */ |
278 | 282 |
|
279 | 283 | /** |
280 | 284 | * Without this, <a>%%</a> would throw an error |
@@ -317,19 +321,15 @@ export function applyToLink(a, currentUrl) { |
317 | 321 | ) { |
318 | 322 | const url = a.textContent; |
319 | 323 | const shortened = shortenRepoUrl(url, currentUrl); |
320 | | - a.replaceChildren( |
321 | | - ...shortened.split( |
322 | | - /<code>([^<]+)<\/code>/g, |
323 | | - ).map((part, i) => { |
324 | | - if (i % 2 === 0) { |
325 | | - return part; |
326 | | - } |
327 | | - |
328 | | - const codeElement = document.createElement('code'); |
329 | | - codeElement.textContent = part; |
330 | | - return codeElement; |
331 | | - }), |
332 | | - ); |
| 324 | + a.replaceChildren(...shortened.split(/<code>([^<]+)<\/code>/g).map((part, i) => { |
| 325 | + if (i % 2 === 0) { |
| 326 | + return part; |
| 327 | + } |
| 328 | + |
| 329 | + const codeElement = document.createElement('code'); |
| 330 | + codeElement.textContent = part; |
| 331 | + return codeElement; |
| 332 | + })); |
333 | 333 | return true; |
334 | 334 | } |
335 | 335 |
|
|
0 commit comments