From a6037e1979477c020b8ecfe65a1441f38fc249ba Mon Sep 17 00:00:00 2001 From: "Dominik Schilling (ocean90)" Date: Tue, 19 Sep 2017 12:40:22 +0000 Subject: [PATCH] TinyMCE: Improve the previews for shortcodes. Merge of [41395] to the 4.3 branch. git-svn-id: https://develop.svn.wordpress.org/branches/4.3@41440 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/mce-view.js | 12 +++++++++--- src/wp-includes/script-loader.php | 3 +++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/js/mce-view.js b/src/wp-includes/js/mce-view.js index c0ae668062..d09d441cd0 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 ( ! force ) { instance = this.getInstance( text ); @@ -424,7 +422,7 @@ var selected = node === editor.selection.getNode(), $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; } @@ -496,6 +494,14 @@ var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver, 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, contentNode ) { var dom = editor.dom, styles = '', diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index 3dc84e7a8e..9448a6a7c7 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -791,6 +791,9 @@ function wp_just_in_time_script_localization() { 'blog_id' => get_current_blog_id(), ) ); + wp_localize_script( 'mce-view', 'mceViewL10n', array( + 'shortcodes' => ! empty( $GLOBALS['shortcode_tags'] ) ? array_keys( $GLOBALS['shortcode_tags'] ) : array() + ) ); } /**