From e6b7c3999b4736715f3fb9e92c81282f1bfcd59e Mon Sep 17 00:00:00 2001
From: Yoan VALLET <ext.sopra.yvallet@grandlyon.com>
Date: Tue, 1 Mar 2022 11:17:24 +0100
Subject: [PATCH] fix: use href for stateToHTML for links

---
 src/components/Editing/CustomEditor.tsx | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/components/Editing/CustomEditor.tsx b/src/components/Editing/CustomEditor.tsx
index 5cca8c77..fa27851c 100644
--- a/src/components/Editing/CustomEditor.tsx
+++ b/src/components/Editing/CustomEditor.tsx
@@ -22,8 +22,23 @@ const CustomEditor: React.FC<CustomEditorProps> = ({
   const [editorState, setEditorState] = useState<EditorState>(baseState)
 
   const handleStateChange = (state: EditorState) => {
+    let options = {
+      entityStyleFn: (entity: any) => {
+        const entityType = entity.get('type').toLowerCase()
+        if (entityType === 'link') {
+          const data = entity.getData()
+          return {
+            element: 'a',
+            attributes: {
+              target: data.targetOption,
+              href: data.href,
+            },
+          }
+        }
+      },
+    }
     setEditorState(state)
-    handleChange(stateToHTML(editorState.getCurrentContent()), editorType)
+    handleChange(stateToHTML(state.getCurrentContent(), options), editorType)
   }
 
   return (
-- 
GitLab