From 825e2e45fe0e33fc8210c372a171b039f52f758f Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Fri, 26 Feb 2016 01:55:33 +0000 Subject: [PATCH] TinyMCE textpattern: fix error when inserting `
` if the new paragraph is not direct child of the body. See #33300. git-svn-id: https://develop.svn.wordpress.org/trunk@36720 602fd350-edb4-49c9-b593-d223f7449a82 --- .../js/tinymce/plugins/wptextpattern/plugin.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js b/src/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js index 375dd849e2..4123fdf1e9 100644 --- a/src/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js @@ -235,7 +235,7 @@ start = rng.startContainer, node = firstTextNode( start ), i = enterPatterns.length, - text, pattern; + text, pattern, parent; if ( ! node ) { return; @@ -273,7 +273,11 @@ editor.formatter.apply( pattern.format, {}, node ); node.replaceData( 0, node.data.length, ltrim( node.data.slice( pattern.start.length ) ) ); } else if ( pattern.element ) { - editor.getBody().replaceChild( document.createElement( pattern.element ), node.parentNode ); + parent = node.parentNode && node.parentNode.parentNode; + + if ( parent ) { + parent.replaceChild( document.createElement( pattern.element ), node.parentNode ); + } } } );