(possibleFeature: HTMLElement)
| 22 | }); |
| 23 | |
| 24 | function linkifyFeature(possibleFeature: HTMLElement): void { |
| 25 | const originalText = possibleFeature.textContent; |
| 26 | const id = getNewFeatureName(originalText); |
| 27 | if (!id) { |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | const href = getFeatureUrl(id); |
| 32 | // If the original text is different from the resolved ID, it's an old name |
| 33 | const isOldName = originalText !== id; |
| 34 | const title = isOldName ? `Now called ${id}` : undefined; |
| 35 | let anchorElement: Element | undefined; |
| 36 | |
| 37 | const possibleLink = possibleFeature.firstElementChild ?? possibleFeature; |
| 38 | if (possibleLink instanceof HTMLAnchorElement) { |
| 39 | // Possible DOM structure: |
| 40 | // - <a> |
| 41 | // - <code> > <a> |
| 42 | possibleLink.href = href; |
| 43 | possibleLink.title = ''; |
| 44 | possibleLink.classList.add('color-fg-accent'); |
| 45 | if (title) { |
| 46 | possibleLink.title = title; |
| 47 | } |
| 48 | |
| 49 | // <sup> goes after the <code> element (outside the inner link) |
| 50 | anchorElement = possibleFeature; |
| 51 | } else if (!closestElementOptional('a', possibleFeature)) { |
| 52 | // Possible DOM structure: |
| 53 | // - <code> |
| 54 | wrap( |
| 55 | possibleFeature, |
| 56 | <a |
| 57 | className="color-fg-accent" |
| 58 | data-turbo-frame="repo-content-turbo-frame" |
| 59 | href={href} |
| 60 | title={title} |
| 61 | />, |
| 62 | ); |
| 63 | // After wrap(), possibleFeature.parentElement is the new <a> |
| 64 | // Mount after the <a> so <sup> is outside the link |
| 65 | anchorElement = possibleFeature.parentElement!; |
| 66 | } |
| 67 | |
| 68 | if (anchorElement && shouldShowCount()) { |
| 69 | const sup = <sup />; |
| 70 | anchorElement.after(sup); |
| 71 | mount(RelatedIssuesCount, { |
| 72 | target: sup, |
| 73 | props: { |
| 74 | featureId: id, |
| 75 | mini: true, |
| 76 | }, |
| 77 | }); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | function init(signal: AbortSignal): void { |
nothing calls this directly
no test coverage detected