Skip to main content
Glama
MessageWithLinks.tsx1.35 kB
// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors // SPDX-License-Identifier: Apache-2.0 import { Text, Anchor } from '@mantine/core'; import type { JSX } from 'react'; interface MessageWithLinksProps { content: string; } export function MessageWithLinks({ content }: MessageWithLinksProps): JSX.Element { const resourcePattern = /\b([A-Z][a-zA-Z]+)\/([a-zA-Z0-9-]+)\b/g; const parts: JSX.Element[] = []; let lastIndex = 0; let match; while ((match = resourcePattern.exec(content)) !== null) { const [fullMatch, resourceType, resourceId] = match; const matchIndex = match.index; if (matchIndex > lastIndex) { parts.push(<span key={`text-${lastIndex}`}>{content.substring(lastIndex, matchIndex)}</span>); } const href = `/${resourceType}/${resourceId}`; parts.push( <Anchor key={`link-${matchIndex}`} href={href} target="_blank" rel="noopener noreferrer" c="#7c3aed" style={{ fontWeight: 500 }} > {fullMatch} </Anchor> ); lastIndex = matchIndex + fullMatch.length; } if (lastIndex < content.length) { parts.push(<span key={`text-${lastIndex}`}>{content.substring(lastIndex)}</span>); } return <Text style={{ whiteSpace: 'pre-wrap' }}>{parts.length > 0 ? parts : content}</Text>; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/medplum/medplum'

If you have feedback or need assistance with the MCP directory API, please join our Discord server