Files
outline/shared/utils/parseMentionUrl.ts
Tom Moor 7dc1d12d3b feat: Support simplified mention syntax in markdown for MCP (#11851)
* feat: Support simplified mention syntax in markdown for MCP clients

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Restore translations

* PR feedback

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-23 08:08:24 -04:00

31 lines
839 B
TypeScript

/**
* Parse a mention:// URL into its components.
*
* Supports both the 3-segment format (mention://id/type/modelId) and the
* 2-segment format (mention://type/modelId).
*
* @param url the mention URL to parse.
* @returns the parsed components, or an empty object if the URL is invalid.
*/
const parseMentionUrl = (
url: string
): { id?: string; mentionType?: string; modelId?: string } => {
const match3 = url.match(
/^mention:\/\/([a-z0-9-]+)\/([a-z_]+)\/([a-z0-9-]+)$/
);
if (match3) {
const [id, mentionType, modelId] = match3.slice(1);
return { id, mentionType, modelId };
}
const match2 = url.match(/^mention:\/\/([a-z_]+)\/([a-z0-9-]+)$/);
if (match2) {
const [mentionType, modelId] = match2.slice(1);
return { mentionType, modelId };
}
return {};
};
export default parseMentionUrl;