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:
parent
601aee103a
commit
e0e4780c9d
|
@ -173,14 +173,21 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( ! event.load ) {
|
||||||
node = editor.selection.getNode();
|
node = editor.selection.getNode();
|
||||||
|
|
||||||
// When a url is pasted, only try to embed it when pasted in an empty paragrapgh.
|
if ( node && node !== editor.getBody() && /^\s*https?:\/\/\S+\s*$/i.test( event.content ) ) {
|
||||||
if ( event.content.match( /^\s*(https?:\/\/[^\s"]+)\s*$/i ) &&
|
// When a url is pasted or inserted, only try to embed it when it is in an empty paragrapgh.
|
||||||
( node.nodeName !== 'P' || node.parentNode !== editor.getBody() || ! editor.dom.isEmpty( node ) ) ) {
|
node = editor.dom.getParent( node, 'p' );
|
||||||
|
|
||||||
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
event.content = wp.mce.views.setMarkers( event.content );
|
event.content = wp.mce.views.setMarkers( event.content );
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue