Skip to content

Commit eefa8e8

Browse files
committed
MC-3722: HTML saved in textarea on stage is getting re-formatted
Add bypass-html-filter and fix its application in filter-html.ts
1 parent 461f77e commit eefa8e8

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

app/code/Magento/PageBuilder/view/adminhtml/web/js/master-format/filter-html.js

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/template/content-type/text/default/master.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
*/
66
-->
77

8-
<div html="data.main.html" attr="data.main.attributes" ko-style="data.main.style" css="data.main.css"></div>
8+
<div html="data.main.html" attr="data.main.attributes" ko-style="data.main.style" css="data.main.css" class="bypass-html-filter"></div>

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/master-format/filter-html.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ export default function filterHtml(element: JQuery): JQuery {
1919
};
2020
element.find("[data-bind]").each((index, value) => { $(value).removeAttr("data-bind"); });
2121
element.contents().filter(isWhiteSpaceOrComment).remove();
22-
element.find("*").each(
23-
(index, value) => {
24-
const isIframe = value.tagName === "IFRAME";
25-
const isBeingBypassedByThisFilter = !!$(value).closest(".bypass-html-filter").length;
26-
if (!isIframe && !isBeingBypassedByThisFilter) {
27-
$(value).contents().filter(isWhiteSpaceOrComment).remove();
28-
}
22+
element.find("*").filter((index, descendentEl) => {
23+
// filter out elements that are iframes or have .bypass-html-filter ancestor
24+
const isIframe = descendentEl.tagName === "IFRAME";
25+
const isBeingBypassedByThisFilter = !!$(descendentEl).closest(".bypass-html-filter").length;
26+
return !isIframe && !isBeingBypassedByThisFilter;
27+
}).each(
28+
(index, descendentEl) => {
29+
$(descendentEl).contents().filter(isWhiteSpaceOrComment).remove();
2930
},
3031
);
3132
element.find("[data-wrapper]").each((index, value) => {

0 commit comments

Comments
 (0)