| 232 | } |
| 233 | |
| 234 | function markCodeLinks(root: HTMLDivElement) { |
| 235 | const codeNodes = Array.from(root.querySelectorAll(":not(pre) > code")) |
| 236 | for (const code of codeNodes) { |
| 237 | const href = codeUrl(code.textContent ?? "") |
| 238 | const parentLink = |
| 239 | code.parentElement instanceof HTMLAnchorElement && code.parentElement.classList.contains("external-link") |
| 240 | ? code.parentElement |
| 241 | : null |
| 242 | |
| 243 | if (!href) { |
| 244 | if (parentLink) parentLink.replaceWith(code) |
| 245 | continue |
| 246 | } |
| 247 | |
| 248 | if (parentLink) { |
| 249 | parentLink.href = href |
| 250 | continue |
| 251 | } |
| 252 | |
| 253 | const link = document.createElement("a") |
| 254 | link.href = href |
| 255 | link.className = "external-link" |
| 256 | link.target = "_blank" |
| 257 | link.rel = "noopener noreferrer" |
| 258 | code.parentNode?.replaceChild(link, code) |
| 259 | link.appendChild(code) |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | function markInlineCode(root: HTMLDivElement) { |
| 264 | const codeNodes = Array.from(root.querySelectorAll(":not(pre) > code")) |