diff --git a/packages/extension-mention/src/mention.ts b/packages/extension-mention/src/mention.ts index c6165f497..18ac31da5 100644 --- a/packages/extension-mention/src/mention.ts +++ b/packages/extension-mention/src/mention.ts @@ -62,6 +62,22 @@ export const Mention = Node.create({ } }, }, + label: { + default: null, + parseHTML: element => { + return { + label: element.getAttribute('data-label'), + }; + }, + renderHTML: attributes => { + if (!attributes.label) { + return {}; + } + return { + 'data-label': attributes.label, + }; + }, + }, } }, @@ -77,12 +93,12 @@ export const Mention = Node.create({ return [ 'span', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), - `${this.options.suggestion.char}${node.attrs.id}`, + `${this.options.suggestion.char}${node.attrs.label ?? node.attrs.id}`, ] }, renderText({ node }) { - return `${this.options.suggestion.char}${node.attrs.id}` + return `${this.options.suggestion.char}${node.attrs.label ?? node.attrs.id}` }, addKeyboardShortcuts() {