diff --git a/src/wp-includes/js/mce-view.js b/src/wp-includes/js/mce-view.js index 5caf8016ba..ec167ca47c 100644 --- a/src/wp-includes/js/mce-view.js +++ b/src/wp-includes/js/mce-view.js @@ -483,11 +483,13 @@ window.wp = window.wp || {}; * @returns {string} */ getHtml: function() { - var attrs = _.defaults( - this.shortcode.attrs.named, - wp.media[ this.shortcode.tag ].defaults - ); - return this.template({ model: attrs }); + var attrs = this.shortcode.attrs.named; + attrs.content = this.shortcode.content; + + return this.template({ model: _.defaults( + attrs, + wp.media[ this.shortcode.tag ].defaults ) + }); }, unbind: function() { diff --git a/src/wp-includes/js/tinymce/plugins/wpview/plugin.js b/src/wp-includes/js/tinymce/plugins/wpview/plugin.js index f357fffc80..4e224b0683 100644 --- a/src/wp-includes/js/tinymce/plugins/wpview/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wpview/plugin.js @@ -332,17 +332,24 @@ tinymce.PluginManager.add( 'wpview', function( editor ) { tinymce.each( dom.select( 'div[data-wpview-text]', event.node ), function( node ) { // Empty the wrap node if ( 'textContent' in node ) { - node.textContent = ''; + node.textContent = '\u00a0'; } else { - node.innerText = ''; + node.innerText = '\u00a0'; } - - // This makes all views into block tags (as we use
). - // Can use 'PostProcess' and a regex instead. - dom.replace( dom.create( 'p', null, window.decodeURIComponent( dom.getAttrib( node, 'data-wpview-text' ) ) ), node ); }); }); + editor.on( 'PostProcess', function( event ) { + if ( event.content ) { + event.content = event.content.replace( /
]*?data-wpview-text="([^"]*)"[^>]*>[\s\S]*?<\/div>/g, function( match, shortcode ) { + if ( shortcode ) { + return '

' + window.decodeURIComponent( shortcode ) + '

'; + } + return ''; // If error, remove the view wrapper + }); + } + }); + editor.on( 'keydown', function( event ) { var keyCode = event.keyCode, body = editor.getBody(),