import { IconHash } from "@tabler/icons-react"; import type { ComponentPropsWithoutRef } from "react"; import type { Components, ExtraProps } from "react-markdown"; import type { EntityReference } from "@/lib/types/entity-reference"; import { entityReferenceHref, entityReferenceLabel, matchEntityReferenceLink, } from "@/lib/entity-references/message-references"; import { markdownComponents } from "@/components/shared/markdown-components"; import { useTranslation } from "react-i18next"; type EntityReferenceChipProps = { reference: EntityReference; }; export function EntityReferenceChip({ reference }: EntityReferenceChipProps) { const { t } = useTranslation(); const label = entityReferenceLabel(reference); const isInternal = reference.url.startsWith("/") || reference.url.startsWith("#"); return ( ); } type EntityReferenceAnchorProps = ComponentPropsWithoutRef<"a"> & ExtraProps & { references: readonly EntityReference[]; }; function EntityReferenceAnchor({ references, children, href, ...props }: EntityReferenceAnchorProps) { const node = props.node; const textChild = node?.children.length === 1 ? node.children[0] : null; const label = textChild?.type === "text" ? textChild.value : null; const reference = label === null ? null : matchEntityReferenceLink(references, label, href); if (reference) return ; const MarkdownAnchor = markdownComponents.a; return ( {children} ); } export function buildEntityReferenceMarkdownComponents( references: readonly EntityReference[], ): Components { if (references.length === 0) return markdownComponents; return { ...markdownComponents, a: (props) => , }; }