more changes for #4134 - ensure HTML content is preserved

This commit is contained in:
sbwalker 2024-04-12 14:58:14 -04:00
parent 8f00730189
commit 39dff1ea7c

View File

@ -109,6 +109,7 @@
private bool _richfilemanager = false; private bool _richfilemanager = false;
private FileManager _fileManager; private FileManager _fileManager;
private string _richhtml = string.Empty; private string _richhtml = string.Empty;
private string _originalrichhtml = string.Empty;
private bool _rawfilemanager = false; private bool _rawfilemanager = false;
private string _rawhtml = string.Empty; private string _rawhtml = string.Empty;
private string _originalrawhtml = string.Empty; private string _originalrawhtml = string.Empty;
@ -156,6 +157,7 @@
_richhtml = Content; _richhtml = Content;
_rawhtml = Content; _rawhtml = Content;
_originalrawhtml = _rawhtml; // preserve for comparison later _originalrawhtml = _rawhtml; // preserve for comparison later
_originalrichhtml = "";
_contentchanged = true; _contentchanged = true;
if (!AllowRichText) if (!AllowRichText)
@ -184,6 +186,9 @@
await interop.LoadEditorContent(_editorElement, _richhtml); 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; _initialized = true;
} }
else else
@ -194,6 +199,7 @@
{ {
// reload if content passed to component has changed // reload if content passed to component has changed
await interop.LoadEditorContent(_editorElement, _richhtml); await interop.LoadEditorContent(_editorElement, _richhtml);
_originalrichhtml = await interop.GetHtml(_editorElement);
} }
else else
{ {
@ -232,18 +238,24 @@
} }
else else
{ {
var richhtml = "";
if (AllowRichText) if (AllowRichText)
{ {
// return rich text content
var interop = new RichTextEditorInterop(JSRuntime); var interop = new RichTextEditorInterop(JSRuntime);
return await interop.GetHtml(_editorElement); richhtml = await interop.GetHtml(_editorElement);
}
if (richhtml != _originalrichhtml && !string.IsNullOrEmpty(richhtml))
{
return richhtml;
} }
else else
{ {
// return original raw html content // return original raw html content
return _originalrawhtml; return _originalrawhtml;
} }
} }
} }
public async Task InsertRichImage() public async Task InsertRichImage()