Add Text and href for Link #5840
Unanswered
pprev94
asked this question in
Questions & Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I 'd like to extend Link; when I click on the button, I'd like to show a dialogbox and enter name and href value and Insert content
Here's my code, commands.insertContent does not insert the link
`type CustomLinkProps = {
href: string;
value: string;
};
export const CustomLink = Link.extend({
addCommands() {
return {
...this.parent?.(),
addLink: function (options: CustomLinkProps) {
return ({ commands }) => {
commands.insertContent(
<a href="${options.href}">${options.value}</a>
, {parseOptions: {
preserveWhitespace: false,
},
});
};
},
};
},
});
const addLink = useCallback(() => {
const url = window.prompt("URL");
if (url) {
editor?.chain().focus().extendMarkRange("link").addLink({ href: url, value: "tvjidjv" });
}
}, [editor]);
`
What's wrong ? Any ideas ?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions