Skip to content

Commit

Permalink
feat: add label attribute to mention extension (#1322)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhrtly authored Jun 14, 2021
1 parent a3a847f commit c3afe88
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions packages/extension-mention/src/mention.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ export const Mention = Node.create<MentionOptions>({
}
},
},
label: {
default: null,
parseHTML: element => {
return {
label: element.getAttribute('data-label'),
};
},
renderHTML: attributes => {
if (!attributes.label) {
return {};
}
return {
'data-label': attributes.label,
};
},
},
}
},

Expand All @@ -77,12 +93,12 @@ export const Mention = Node.create<MentionOptions>({
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() {
Expand Down

0 comments on commit c3afe88

Please sign in to comment.