MCPcopy Create free account
hub / github.com/anomalyco/opencode / markCodeLinks

Function markCodeLinks

packages/session-ui/src/components/markdown.tsx:234–261  ·  view source on GitHub ↗
(root: HTMLDivElement)

Source from the content-addressed store, hash-verified

232}
233
234function 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
263function markInlineCode(root: HTMLDivElement) {
264 const codeNodes = Array.from(root.querySelectorAll(":not(pre) > code"))

Callers 1

decorateFunction · 0.85

Calls 2

codeUrlFunction · 0.85
fromMethod · 0.45

Tested by

no test coverage detected