At IndyRiot, we use TipTap as our rich text WYSIWYG editor. We use the mention extension to allow users to tag other users, driving engagement and helping communities thrive.
By default, the mention extension does not include support for linking to other content. However, it is easy to create your own mention extension and add this feautre.
- Copy the whole mention extension file from here into your project
- Remove the existing extension-mention import and import your own
- Modify the renderHTML function to swap 'span' for 'a'
- Add a href to mergeAttributes, using a value from your suggestion function
- Done!
renderHTML({ node, HTMLAttributes }) {
return [
'a',
mergeAttributes({ 'data-type': this.name }, { 'href': `/user/${HTMLAttributes['data-id']}` }, this.options.HTMLAttributes, HTMLAttributes),
this.options.renderLabel({
options: this.options,
node,
}),
]
},
Thanks for Reading!
I always appreciate feedback or suggestions for future blog posts. You can find me on LinkedIn or if you want to improve the article to help future readers, please feel free to submit a PR.