From 3a2cbbdc28fae2409ff135e2c88f6cde11c91f32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marker=20dao=20=C2=AE?= Date: Thu, 7 Nov 2024 15:01:40 +0100 Subject: [PATCH] HtmlEditor: Apply converter on init --- .../ui/html_editor/m_html_editor.ts | 25 ++++--- packages/devextreme/playground/jquery.html | 65 +++++++++++++++---- 2 files changed, 70 insertions(+), 20 deletions(-) diff --git a/packages/devextreme/js/__internal/ui/html_editor/m_html_editor.ts b/packages/devextreme/js/__internal/ui/html_editor/m_html_editor.ts index 9fe17a38b91c..6e6480f7f00f 100644 --- a/packages/devextreme/js/__internal/ui/html_editor/m_html_editor.ts +++ b/packages/devextreme/js/__internal/ui/html_editor/m_html_editor.ts @@ -70,6 +70,15 @@ const HtmlEditor = Editor.inherit({ this.callBase(); this._cleanCallback = Callbacks(); this._contentInitializedCallback = Callbacks(); + this._prepareHtmlConverter(); + }, + + _prepareHtmlConverter(): void { + const { converter } = this.option(); + + if (converter) { + this._htmlConverter = converter; + } }, _getAnonymousTemplateName() { @@ -230,10 +239,14 @@ const HtmlEditor = Editor.inherit({ _updateContainerMarkup() { const { value } = this.option(); - if (value) { - const sanitizedMarkup = this._removeXSSVulnerableHtml(value); - this._$htmlContainer.html(sanitizedMarkup); + if (!value) { + return; } + + const html = this._htmlConverter?.toHtml?.(value) || value; + const sanitizedHtml = this._removeXSSVulnerableHtml(html); + + this._$htmlContainer.html(sanitizedHtml); }, _render() { @@ -262,12 +275,6 @@ const HtmlEditor = Editor.inherit({ this._deltaConverter = new DeltaConverter(); } } - - const { converter } = this.option(); - - if (converter) { - this._htmlConverter = converter; - } }, _renderContentImpl() { diff --git a/packages/devextreme/playground/jquery.html b/packages/devextreme/playground/jquery.html index fde766f17218..23152af46ed5 100644 --- a/packages/devextreme/playground/jquery.html +++ b/packages/devextreme/playground/jquery.html @@ -16,11 +16,29 @@ document.getElementsByTagName("head")[0].appendChild(link); + + - + - + - + @@ -51,12 +69,37 @@

Te