@@ -8,10 +8,14 @@ import events from "Magento_PageBuilder/js/events";
88import _ from "underscore" ;
99import HideShowOption from "../../content-type-menu/hide-show-option" ;
1010import { OptionsInterface } from "../../content-type-menu/option.types" ;
11+ import { DataObject } from "../../data-store" ;
1112import delayUntil from "../../utils/delay-until" ;
1213import {
13- createBookmark , createDoubleClickEvent ,
14- findNodeIndex , getActiveEditor , getNodeByIndex ,
14+ createBookmark ,
15+ createDoubleClickEvent ,
16+ findNodeIndex ,
17+ getActiveEditor ,
18+ getNodeByIndex ,
1519 isWysiwygSupported ,
1620 lockImageSize ,
1721 moveToBookmark ,
@@ -300,6 +304,18 @@ export default class Preview extends BasePreview {
300304 protected bindEvents ( ) {
301305 super . bindEvents ( ) ;
302306
307+ this . contentType . dataStore . subscribe ( ( state : DataObject ) => {
308+ // Find html elements which attributes contain magento variables directives
309+ const sanitizedContent = state . content . replace ( / < ( [ a - z 0 - 9 \- \_ ] + ) ( [ ^ > ] + ?[ a - z 0 - 9 \- \_ ] + = " [ ^ " ] * ?\{ \{ .+ ?\} \} .* ?" .* ?) > / gi, ( match1 : string , tag : string , attributes : string ) => {
310+ // Replace double quote with single quote within magento variable directive
311+ const sanitizedAttributes = attributes . replace ( / \{ \{ [ ^ \{ \} ] + \} \} / gi, ( match2 : string ) => match2 . replace ( / " / g, "'" ) ) ;
312+ return "<" + tag + sanitizedAttributes + ">" ;
313+ } ) ;
314+ if ( sanitizedContent !== state . content ) {
315+ state . content = sanitizedContent ;
316+ }
317+ } ) ;
318+
303319 // After drop of new content type open TinyMCE and focus
304320 events . on ( "text:dropAfter" , ( args : ContentTypeMountEventParamsInterface ) => {
305321 if ( args . id === this . contentType . id ) {
0 commit comments