<!-- source-hash: dab5bf3f8a2e52f871c282c3d6212649 -->
A remark plugin for the unified/react-markdown pipeline that transforms `[card://<type>:<id>]` markers in markdown text nodes into synthetic `link` mdast nodes with a `card://` URL scheme, enabling downstream component overrides to render entity cards.

## Key Components

- **`CARD_REGEX`** — Global regex matching `[card://type:id]` patterns, intentionally tolerating both `]` and `)` as closing characters to handle LLM bracket-balancing drift on opaque token IDs (e.g. UUIDs)
- **`remarkCardLinks`** — Unified `Plugin<[], Root>` factory; visits all `text` leaves in the mdast tree and splits them into interleaved `Text` and `Link` nodes where card markers are found
- **`card://` URL scheme** — Non-standard scheme placed on the synthetic link's `url` so the `<a>` component override in `chat-message-enhanced.tsx` can detect and delegate rendering to `renderEntityCard`

## Usage Example

```typescript
import ReactMarkdown from "react-markdown"
import { remarkCardLinks } from "./remark-card-links"

// The plugin is registered in the remark pipeline:
<ReactMarkdown
  remarkPlugins={[remarkCardLinks]}
  components={{
    a({ href, children }) {
      if (href?.startsWith("card://")) {
        const [, cardType, cardId] = href.split(/[:/]+/)
        return renderEntityCard(cardType, cardId)
      }
      return <a href={href}>{children}</a>
    },
  }}
>
  {`**The [card://webinar:42] discussed pricing**`}
</ReactMarkdown>
// bold wrapper is preserved; only the text leaf is split
```

## Notes

- Operates on text leaves only — bold, italic, list, and code wrappers around markers are preserved untouched
- Resets `CARD_REGEX.lastIndex` per invocation to avoid stale state from the `g` flag
- Returns `[SKIP, index + parts.length]` after splicing to prevent the visitor from re-entering the newly inserted nodes