diff --git a/admin/src/components/ReactMdEditor/index.js b/admin/src/components/ReactMdEditor/index.js index ca7fadc..9db6639 100644 --- a/admin/src/components/ReactMdEditor/index.js +++ b/admin/src/components/ReactMdEditor/index.js @@ -74,19 +74,24 @@ const Editor = ({ let newValue = value ? value : ""; assets.map((asset) => { if (asset.mime.includes("image")) { - const imgTag = ` ![${asset.alt}](${asset.url}) `; + const imgTag = `![${asset.alt}](${asset.url})`; if (mediaLibSelection > -1) { - newValue = - value.substring(0, mediaLibSelection) + - imgTag + - value.substring(mediaLibSelection); + const preValue = value?.substring(0, mediaLibSelection) ?? ""; + const postValue = value?.substring(mediaLibSelection) ?? ""; + newValue = `${ + preValue && !preValue.endsWith(" ") ? preValue + " " : preValue + }${imgTag}${ + postValue && !postValue.startsWith(" ") + ? " " + postValue + : postValue + }`; } else { newValue = `${newValue}${imgTag}`; } } // Handle videos and other type of files by adding some code }); - onChange({ target: { name, value: newValue || "" } }); + onChange({ target: { name, value: newValue ?? "" } }); handleToggleMediaLib(); }; diff --git a/package.json b/package.json index 16ca781..12694ab 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "strapi-plugin-wysiwyg-react-md-editor", - "version": "4.4.0", + "version": "4.4.1", "description": "Replaces the default Strapi WYSIWYG editor with react md editor.", "strapi": { "name": "wysiwyg-react-md-editor",