diff --git a/modules/ve-mw/tests/ui/datatransferhandlers/ve.ui.MWWikitextStringTransferHandler.test.js b/modules/ve-mw/tests/ui/datatransferhandlers/ve.ui.MWWikitextStringTransferHandler.test.js index 726c0b2ba8..9de0ef131a 100644 --- a/modules/ve-mw/tests/ui/datatransferhandlers/ve.ui.MWWikitextStringTransferHandler.test.js +++ b/modules/ve-mw/tests/ui/datatransferhandlers/ve.ui.MWWikitextStringTransferHandler.test.js @@ -9,16 +9,18 @@ QUnit.module( 've.ui.MWWikitextStringTransferHandler', QUnit.newMwEnvironment( { setup: function () { // Mock XHR for mw.Api() this.server = MWWIKITEXT_MOCK_API ? this.sandbox.useFakeServer() : null; - } + ve.test.utils.mwEnvironment.setup.call( this ); + }, + teardown: ve.test.utils.mwEnvironment.teardown } ) ); /* Tests */ -function runWikitextStringHandlerTest( assert, server, string, mimeType, expectedResponse, expectedData, annotations, msg ) { +function runWikitextStringHandlerTest( assert, server, string, mimeType, expectedResponse, expectedData, annotations, assertDom, msg ) { var handler, i, j, name, done = assert.async(), item = ve.ui.DataTransferItem.static.newFromString( string, mimeType ), - doc = ve.dm.example.createExampleDocument(), + doc = new ve.dm.Document( [] ), mockSurface = { getModel: function () { return { @@ -53,7 +55,11 @@ function runWikitextStringHandlerTest( assert, server, string, mimeType, expecte handler.getInsertableData().done( function ( doc2 ) { var actualData = doc2.getData(); ve.dm.example.postprocessAnnotations( actualData, doc2.getStore() ); - assert.equalLinearData( actualData, expectedData, msg + ': data match' ); + if ( assertDom ) { + assert.equalLinearDataWithDom( doc2.getStore(), actualData, expectedData, msg + ': data match (with DOM)' ); + } else { + assert.equalLinearData( actualData, expectedData, msg + ': data match' ); + } done(); } ); @@ -144,21 +150,19 @@ QUnit.test( 'convert', function ( assert ) { ] }, { - msg: 'Heading', + msg: 'Headings, only RESTBase IDs stripped', pasteString: '==heading==', pasteType: 'text/plain', - parsoidResponse: '

heading

', + parsoidResponse: '

foo

bar

', annotations: [], + assertDom: true, expectedData: [ - { type: 'heading', attributes: { level: 2 } }, - 'h', - 'e', - 'a', - 'd', - 'i', - 'n', - 'g', - { type: '/heading' }, + { type: 'mwHeading', attributes: { level: 2 }, originalDomElements: $( '

foo

' ).toArray() }, + 'f', 'o', 'o', + { type: '/mwHeading' }, + { type: 'mwHeading', attributes: { level: 2 }, originalDomElements: $( '

bar

' ).toArray() }, + 'b', 'a', 'r', + { type: '/mwHeading' }, { type: 'internalList' }, { type: '/internalList' } ] @@ -296,6 +300,9 @@ QUnit.test( 'convert', function ( assert ) { QUnit.expect( cases.length * 2 ); for ( i = 0; i < cases.length; i++ ) { - runWikitextStringHandlerTest( assert, this.server, cases[ i ].pasteString, cases[ i ].pasteType, cases[ i ].parsoidResponse, cases[ i ].expectedData, cases[ i ].annotations, cases[ i ].msg ); + runWikitextStringHandlerTest( + assert, this.server, cases[ i ].pasteString, cases[ i ].pasteType, cases[ i ].parsoidResponse, + cases[ i ].expectedData, cases[ i ].annotations, cases[ i ].assertDom, cases[ i ].msg + ); } } ); diff --git a/modules/ve-mw/ui/datatransferhandlers/ve.ui.MWWikitextStringTransferHandler.js b/modules/ve-mw/ui/datatransferhandlers/ve.ui.MWWikitextStringTransferHandler.js index 1138852803..74e8dc074f 100644 --- a/modules/ve-mw/ui/datatransferhandlers/ve.ui.MWWikitextStringTransferHandler.js +++ b/modules/ve-mw/ui/datatransferhandlers/ve.ui.MWWikitextStringTransferHandler.js @@ -96,7 +96,7 @@ ve.ui.MWWikitextStringTransferHandler.prototype.process = function () { // Don't immediately chain, as this.parsoidRequest must be abortable this.parsoidRequest.then( function ( response ) { - var htmlDoc, doc, surface; + var htmlDoc, doc, surface, elementsWithIds, len; if ( ve.getProp( response, 'visualeditor', 'result' ) !== 'success' ) { return failure(); @@ -104,6 +104,14 @@ ve.ui.MWWikitextStringTransferHandler.prototype.process = function () { htmlDoc = ve.createDocumentFromHtml( response.visualeditor.content ); + // Strip RESTBase IDs + elementsWithIds = htmlDoc.querySelectorAll( '[id]' ); + for ( i = 0, len = elementsWithIds.length; i < len; i++ ) { + if ( elementsWithIds[ i ].getAttribute( 'id' ).match( ve.init.platform.getMetadataIdRegExp() ) ) { + elementsWithIds[ i ].removeAttribute( 'id' ); + } + } + // Pass an empty object for the second argument (importRules) so that clipboard mode is used // TODO: Fix that API doc = handler.surface.getModel().getDocument().newFromHtml( htmlDoc, {} );