Skip to content

How to wrap image with a link? #976

Answered by vimtor
vimtor asked this question in Q&A
Aug 31, 2021 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

I ended up creating a custom imagePlugin which renders a image wrapped in a link.

Then for wrapping the image I just check if the selected node is an image and remove it and insert a new image link element from the plugin. Something like this:

const [selectedNode] = getAbove(editor);

if (selectedNode?.type === 'img') {
    Transforms.removeNodes(editor, { at: editor.selection });
    insertImageLink(editor, { url: selectedNode?.url, href: url });
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@woojunro
Comment options

Answer selected by vimtor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants