From 39dff1ea7cc7ee119ddc36f510ad0e8d385b6d73 Mon Sep 17 00:00:00 2001 From: sbwalker Date: Fri, 12 Apr 2024 14:58:14 -0400 Subject: [PATCH] more changes for #4134 - ensure HTML content is preserved --- .../Modules/Controls/RichTextEditor.razor | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/Oqtane.Client/Modules/Controls/RichTextEditor.razor b/Oqtane.Client/Modules/Controls/RichTextEditor.razor index 6da97020..0850325d 100644 --- a/Oqtane.Client/Modules/Controls/RichTextEditor.razor +++ b/Oqtane.Client/Modules/Controls/RichTextEditor.razor @@ -109,6 +109,7 @@ private bool _richfilemanager = false; private FileManager _fileManager; private string _richhtml = string.Empty; + private string _originalrichhtml = string.Empty; private bool _rawfilemanager = false; private string _rawhtml = string.Empty; private string _originalrawhtml = string.Empty; @@ -156,6 +157,7 @@ _richhtml = Content; _rawhtml = Content; _originalrawhtml = _rawhtml; // preserve for comparison later + _originalrichhtml = ""; _contentchanged = true; if (!AllowRichText) @@ -184,6 +186,9 @@ await interop.LoadEditorContent(_editorElement, _richhtml); + // preserve a copy of the rich text content (Quill sanitizes content so we need to retrieve it from the editor as it may have changed) + _originalrichhtml = await interop.GetHtml(_editorElement); + _initialized = true; } else @@ -194,6 +199,7 @@ { // reload if content passed to component has changed await interop.LoadEditorContent(_editorElement, _richhtml); + _originalrichhtml = await interop.GetHtml(_editorElement); } else { @@ -232,18 +238,24 @@ } else { + var richhtml = ""; + if (AllowRichText) { - // return rich text content var interop = new RichTextEditorInterop(JSRuntime); - return await interop.GetHtml(_editorElement); + richhtml = await interop.GetHtml(_editorElement); + } + + if (richhtml != _originalrichhtml && !string.IsNullOrEmpty(richhtml)) + { + return richhtml; } else { - // return original raw html content - return _originalrawhtml; + // return original raw html content + return _originalrawhtml; } - } + } } public async Task InsertRichImage()