From f97c9838d56bdfe637d60086a8cbf6295998a767 Mon Sep 17 00:00:00 2001 From: "Dominik Schilling (ocean90)" Date: Tue, 19 Sep 2017 12:40:10 +0000 Subject: [PATCH] TinyMCE: Improve the previews for shortcodes. Merge of [41395] to the 4.7 branch. git-svn-id: https://develop.svn.wordpress.org/branches/4.7@41436 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/mce-view.js | 12 +++++++++--- src/wp-includes/script-loader.php | 4 ++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/js/mce-view.js b/src/wp-includes/js/mce-view.js index e48611fe35..92273b403e 100644 --- a/src/wp-includes/js/mce-view.js +++ b/src/wp-includes/js/mce-view.js @@ -155,8 +155,6 @@ encodedText, instance; - text = tinymce.DOM.decode( text ); - if ( text.indexOf( '[' ) !== -1 && text.indexOf( ']' ) !== -1 ) { // Looks like a shortcode? Remove any line breaks from inside of shortcodes // or autop will replace them with

and
later and the string won't match. @@ -430,7 +428,7 @@ this.getMarkers( function( editor, node ) { var $viewNode; - if ( ! this.loader && $( node ).text() !== this.text ) { + if ( ! this.loader && $( node ).text() !== tinymce.DOM.decode( this.text ) ) { editor.dom.setAttrib( node, 'data-wpview-marker', null ); return; } @@ -494,6 +492,14 @@ setIframes: function( head, body, callback, rendered ) { var self = this; + if ( body.indexOf( '[' ) !== -1 && body.indexOf( ']' ) !== -1 ) { + var shortcodesRegExp = new RegExp( '\\[\\/?(?:' + window.mceViewL10n.shortcodes.join( '|' ) + ')[^\\]]*?\\]', 'g' ); + // Escape tags inside shortcode previews. + body = body.replace( shortcodesRegExp, function( match ) { + return match.replace( //g, '>' ); + } ); + } + this.getNodes( function( editor, node ) { var dom = editor.dom, styles = '', diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index b9b2bdbcac..44054f47d2 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -938,6 +938,10 @@ function wp_just_in_time_script_localization() { 'autosaveInterval' => AUTOSAVE_INTERVAL, 'blog_id' => get_current_blog_id(), ) ); + + wp_localize_script( 'mce-view', 'mceViewL10n', array( + 'shortcodes' => ! empty( $GLOBALS['shortcode_tags'] ) ? array_keys( $GLOBALS['shortcode_tags'] ) : array() + ) ); } /**