TinyMCE: revert stripping of tags from pasted URLs on `beforeSetContent` [31817] and [31819]. Clean up URLs on `pastePreProcess`.
See #31158. git-svn-id: https://develop.svn.wordpress.org/trunk@31832 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
cc0e582a67
commit
e977f42a66
|
@ -167,41 +167,38 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
|
|||
// matching view patterns, and transform the matches into
|
||||
// view wrappers.
|
||||
editor.on( 'BeforeSetContent', function( event ) {
|
||||
var pastedStr = event.content,
|
||||
trim = tinymce.trim,
|
||||
node;
|
||||
var node;
|
||||
|
||||
if ( ! pastedStr ) {
|
||||
if ( ! event.content ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( selected ) {
|
||||
removeView( selected );
|
||||
}
|
||||
|
||||
node = editor.selection.getNode();
|
||||
|
||||
pastedStr = pastedStr.replace( /<[^>]+>/g, '' );
|
||||
pastedStr = trim( pastedStr );
|
||||
|
||||
// When a url is pasted, only try to embed it when pasted in an empty paragrapgh.
|
||||
if ( /^https?:\/\/\S+$/i.test( pastedStr ) ) {
|
||||
event.content = pastedStr;
|
||||
if ( event.content.match( /^\s*(https?:\/\/[^\s"]+)\s*$/i ) &&
|
||||
( node.nodeName !== 'P' || node.parentNode !== editor.getBody() || ! editor.dom.isEmpty( node ) ) ) {
|
||||
|
||||
node = editor.dom.getParent( node, function( node ) {
|
||||
if ( node.parentNode === editor.getBody() ) {
|
||||
return node;
|
||||
}
|
||||
} );
|
||||
|
||||
if ( node.nodeName !== 'P' || trim( node.textContent || node.innerText ) ) {
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
event.content = wp.mce.views.setMarkers( event.content );
|
||||
});
|
||||
|
||||
// When pasting strip all tags and check if the string is an URL.
|
||||
// Then replace the pasted content with the cleaned URL.
|
||||
editor.on( 'pastePreProcess', function( event ) {
|
||||
var pastedStr = event.content;
|
||||
|
||||
if ( pastedStr ) {
|
||||
pastedStr = tinymce.trim( pastedStr.replace( /<[^>]+>/g, '' ) );
|
||||
|
||||
if ( /^https?:\/\/\S+$/i.test( pastedStr ) ) {
|
||||
event.content = pastedStr;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// When the editor's content has been updated and the DOM has been
|
||||
// processed, render the views in the document.
|
||||
editor.on( 'SetContent', function() {
|
||||
|
|
Loading…
Reference in New Issue