Files
Stephen Zhouandautofix-ci[bot] 226110d611 feat(web): set up @dify/openapi-content-mapper foundations (#44627)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-10-26 05:06:34 +00:00

25 lines
915 B
JavaScript

/** Read explicitly labeled backend links; leave other hover documentation links alone. */
function backendLocations(contents) {
const locations = new Map()
for (const content of contents) {
const markdown = typeof content === 'string' ? content : content.value
if (typeof markdown !== 'string') continue
for (const match of markdown.matchAll(
/\[Open backend implementation\]\((file:\/\/[^\s)]+)#L([1-9]\d*)\)/g,
)) {
const line = Number(match[2])
if (!Number.isSafeInteger(line)) continue
try {
const url = new URL(match[1])
if (url.protocol !== 'file:' || url.search || url.hash) continue
locations.set(`${url.href}#${line}`, { uri: url.href, line })
} catch {
// Malformed optional metadata must not interfere with normal TS navigation.
}
}
}
return [...locations.values()]
}
module.exports = { backendLocations }