diff --git a/src/components/Editor/index.jsx b/src/components/Editor/index.jsx index f151ded6..282419a9 100644 --- a/src/components/Editor/index.jsx +++ b/src/components/Editor/index.jsx @@ -11,6 +11,7 @@ import { Label } from "neetoui"; import ErrorWrapper from "components/Common/ErrorWrapper"; import useEditorWarnings from "hooks/useEditorWarnings"; import "src/styles/editor/index.scss"; +import { removeEmptyTags } from "src/utils"; import { DEFAULT_EDITOR_OPTIONS } from "./constants"; import CharacterCountWrapper from "./CustomExtensions/CharacterCount"; @@ -107,6 +108,14 @@ const Editor = ( 100 ); + const handleBlur = props => { + const { editor } = props; + const trimmedContent = removeEmptyTags(editor.getHTML()); + + onChange(trimmedContent); + onBlur(props); + }; + const customExtensions = useCustomExtensions({ placeholder, extensions, @@ -169,7 +178,7 @@ const Editor = ( onCreate: ({ editor }) => !autoFocus && setInitialPosition(editor), onUpdate: debouncedOnChangeHandler, onFocus, - onBlur, + onBlur: handleBlur, }); useEditorState({ diff --git a/src/components/EditorContent/index.jsx b/src/components/EditorContent/index.jsx index 032c83da..2df9a58d 100644 --- a/src/components/EditorContent/index.jsx +++ b/src/components/EditorContent/index.jsx @@ -8,6 +8,7 @@ import { createRoot } from "react-dom/client"; import { EDITOR_SIZES } from "src/common/constants"; import "src/styles/editor/editor-content.scss"; +import { removeEmptyTags } from "utils"; import { EDITOR_CONTENT_CLASS_NAME, @@ -34,7 +35,7 @@ const EditorContent = ({ const editorContentRef = useRef(null); const htmlContent = substituteVariables( - applySyntaxHighlightingAndLineNumbers(content), + applySyntaxHighlightingAndLineNumbers(removeEmptyTags(content)), variables ); const sanitize = DOMPurify.sanitize;