Skip to content

Mention markdown support #4467

@zbeyens

Description

@zbeyens

Discussed in #4451

Originally posted by maayanalgresie July 3, 2025
Hi,

In the examples, I see that the markdown supports mentions of the type @FIRST or @first-second, but I need to mention full names that include spaces (e.g., @FIRST Last).

Is there a markdown format that supports mentions with spaces in the display name?
Or would I need to implement a custom parsing rule to handle this?

Thanks!

[placeholder](type:value) is a good pattern, for example Cursor mdc links uses that: [component.tsx](mdc:src/components/example/component.tsx)

@[zbeyens](https://github.com/zbeyens)
zbeyens
[yesterday](https://github.com/udecode/plate/discussions/4451#discussioncomment-13673676)
Maintainer
Here's the regex for parsing text format:

  // Basic regex
  const mentionRegex = /\[([^\]]+)\]\(mention:([^)]+)\)/g;

  // With capture groups:
  // $1 = display text
  // $2 = mention id

  // Example usage:
  const text = "Hello [John Doe](mention:user_123), check [Button.tsx](mention:file_abc)";

  // Parse all mentions
  const mentions = Array.from(text.matchAll(mentionRegex)).map(match => ({
    fullMatch: match[0],
    displayText: match[1],
    id: match[2],
    index: match.index
  }));

  // Replace mentions with custom rendering
  const rendered = text.replace(mentionRegex, (match, displayText, id) => {
    if (id.startsWith('user_')) {
      return `<span class="mention-user">@${displayText}</span>`;
    }
    if (id.startsWith('file_')) {
      return `<span class="mention-file">${displayText}</span>`;
    }
    return displayText;
  });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions