diff --git a/src/editors/sharedComponents/InsertLinkModal/index.jsx b/src/editors/sharedComponents/InsertLinkModal/index.jsx index 2a2c7c163..dbef536de 100644 --- a/src/editors/sharedComponents/InsertLinkModal/index.jsx +++ b/src/editors/sharedComponents/InsertLinkModal/index.jsx @@ -54,6 +54,7 @@ const InsertLinkModal = ({ const editor = editorRef.current; const urlPath = blockSelected?.lmsWebUrl || inputUrlValue; const blockId = blockSelected?.blockId; + const linkRegex = /]*><\/a>/gi; if (editor && urlPath) { const validateUrl = isValidURL(urlPath); @@ -78,12 +79,19 @@ const InsertLinkModal = ({ selectedRange.insertNode(newLinkNode); // Remove empty "a" tags after replacing URLs const editorContent = editor.getContent(); - const modifiedContent = editorContent.replace(/]*><\/a>/gi, ''); + const modifiedContent = editorContent.replace(linkRegex, ''); editor.setContent(modifiedContent); dispatch(actions.addBlock({ [blockId]: blockSelected })); } + if(!blockId){ + editor.execCommand('unlink'); + const editorContent = editor.getContent(); + const modifiedContent = editorContent.replace(linkRegex, ''); + editor.setContent(modifiedContent); + } + onClose(); };