TinyMCE: when pasting an URL, check if the node it is pasted at is empty and remove any empty inline child elements.

Fixes #31158.

git-svn-id: https://develop.svn.wordpress.org/trunk@31856 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz 2015-03-20 20:33:55 +00:00
parent 601aee103a
commit e0e4780c9d
1 changed files with 12 additions and 5 deletions

View File

@ -173,13 +173,20 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
return;
}
node = editor.selection.getNode();
if ( ! event.load ) {
node = editor.selection.getNode();
// When a url is pasted, only try to embed it when pasted in an empty paragrapgh.
if ( event.content.match( /^\s*(https?:\/\/[^\s"]+)\s*$/i ) &&
( node.nodeName !== 'P' || node.parentNode !== editor.getBody() || ! editor.dom.isEmpty( node ) ) ) {
if ( node && node !== editor.getBody() && /^\s*https?:\/\/\S+\s*$/i.test( event.content ) ) {
// When a url is pasted or inserted, only try to embed it when it is in an empty paragrapgh.
node = editor.dom.getParent( node, 'p' );
return;
if ( node && /^[\s\uFEFF\u00A0]*$/.test( node.textContent || node.innerText ) ) {
// Make sure there are no empty inline elements in the <p>
node.innerHTML = '';
} else {
return;
}
}
}
event.content = wp.mce.views.setMarkers( event.content );