TinyMCE: Improve the previews for shortcodes.

git-svn-id: https://develop.svn.wordpress.org/trunk@41395 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dominik Schilling (ocean90) 2017-09-19 08:18:15 +00:00
parent 1f0d51dbd2
commit 49540b271c
2 changed files with 13 additions and 3 deletions

View File

@ -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 <p> and <br> later and the string won't match.
@ -431,7 +429,7 @@
var selected = node === editor.selection.getNode();
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;
}
@ -502,6 +500,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, '&lt;' ).replace( />/g, '&gt;' );
} );
}
this.getNodes( function( editor, node ) {
var dom = editor.dom,
styles = '',

View File

@ -1058,6 +1058,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()
) );
}
/**