@@ -8,10 +8,14 @@ import events from "Magento_PageBuilder/js/events";
8
8
import _ from "underscore" ;
9
9
import HideShowOption from "../../content-type-menu/hide-show-option" ;
10
10
import { OptionsInterface } from "../../content-type-menu/option.types" ;
11
+ import { DataObject } from "../../data-store" ;
11
12
import delayUntil from "../../utils/delay-until" ;
12
13
import {
13
- createBookmark , createDoubleClickEvent ,
14
- findNodeIndex , getActiveEditor , getNodeByIndex ,
14
+ createBookmark ,
15
+ createDoubleClickEvent ,
16
+ findNodeIndex ,
17
+ getActiveEditor ,
18
+ getNodeByIndex ,
15
19
isWysiwygSupported ,
16
20
lockImageSize ,
17
21
moveToBookmark ,
@@ -300,6 +304,18 @@ export default class Preview extends BasePreview {
300
304
protected bindEvents ( ) {
301
305
super . bindEvents ( ) ;
302
306
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
+
303
319
// After drop of new content type open TinyMCE and focus
304
320
events . on ( "text:dropAfter" , ( args : ContentTypeMountEventParamsInterface ) => {
305
321
if ( args . id === this . contentType . id ) {
0 commit comments