function renderMessageWithEmbeddedLinks()

in components/RunCard.renderCell.tsx [156:180]


function renderMessageWithEmbeddedLinks(result: Result, message: string) {
	const rxLink = /\[([^\]]*)\]\(([^\)]+)\)/ // Matches [text](id). Similar to below, but with an extra grouping around the id part.
	return message.match(rxLink)
		? message
			.split(/(\[[^\]]*\]\([^\)]+\))/g)
			.map((item, i) => {
				if (i % 2 === 0) return item
				const [_, text, id] = item.match(rxLink)

				const href = (() => {
					if (isNaN(id as any)) return id // `id` is a URI string

					// Else `id` is a number
					// TODO: search other location coolections
					// RelatedLocations is typically [{ id: 1, ...}, { id: 2, ...}]
					const physicalLocation = result.relatedLocations?.find(location => location.id === +id)?.physicalLocation
					return getRepoUri(physicalLocation?.artifactLocation?.uri, result.run, physicalLocation?.region)
				})()

				return href
					? <a key={i} href={href} target="_blank">{text}</a>
					: text
			})
		: message
}