(element: HTMLElement)
| 118 | } |
| 119 | |
| 120 | export function linkifyUrls(element: HTMLElement): void { |
| 121 | if (element.textContent.length < 15) { // Must be long enough for a URL |
| 122 | return; |
| 123 | } |
| 124 | |
| 125 | if (elementExists(linkifiedUrlSelector, element)) { |
| 126 | console.warn('Links already exist', element); |
| 127 | throw new Error('Links already exist'); |
| 128 | } |
| 129 | |
| 130 | const linkified = linkifyUrlsToDom(element.textContent, { |
| 131 | attributes: { |
| 132 | rel: 'noreferrer noopener', |
| 133 | class: linkifiedUrlClass, // Necessary to avoid also shortening the links |
| 134 | }, |
| 135 | }); |
| 136 | |
| 137 | if (linkified.children.length === 0) { // Children are <a> |
| 138 | return; |
| 139 | } |
| 140 | |
| 141 | zipTextNodes(element, linkified); |
| 142 | repositionAnchors(element); |
| 143 | } |
| 144 | |
| 145 | export function parseBackticks(element: Element): void { |
| 146 | for (const node of getTextNodes(element)) { |
no test coverage detected