In ve.ui.MWWikitextStringTransferHandler#process we create, and return, invalid documents containing bare content not wrapped in a content branch node:
// Attempt to undo outermost p-wrapping if possible try { surface.change( ve.dm.TransactionBuilder.static.newFromWrap( doc, new ve.Range( 0, doc.data.countNonInternalElements() ), [], [], [ { type: 'paragraph' } ], [] ) ); } catch ( e ) { // Sometimes there is no p-wrapping, for example: "* foo" // Sometimes there are multiple <p> tags in the output. // That's okay: ignore the error and paste what we've got. } handler.resolve( doc );
This breaks VisualEditor's "no mixed content" paradigm. That can cause problems in a number of places. An immediate problem is that it's incompatible with TreeModifier, but fundamentally there are many reasons we shouldn't create documents like this.
Steps to reproduce:
- Open a blank mediawiki page in VisualEditor
- Open the inspector, and in ve.ui.MWWikitextStringTransferHandler put a breakpoint at handler.resolve( doc ) above
- From somewhere else, copy this plaintext: foo [[bar]] baz
- Paste it into VisualEditor
- Look at doc.data.data
Observed behaviour: The document data is ill-formed; it starts [ 'f', 'o', 'o', ... ] with no enclosing paragraph
Expected behaviour: The document data is well-formed; content only occurs inside ContentBranchNodes