feat: add label attribute to mention extension (#1322)

This commit is contained in:
Tom Hartley
2021-06-14 15:13:06 +01:00
committed by GitHub
parent a3a847f711
commit c3afe880ae

View File

@@ -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,
};
},
},
}
},
@@ -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() {