Page MenuHomePhabricator
Paste P10018

(An Untitled Masterwork)
ActivePublic

Authored by matmarex on Jan 1 2020, 3:52 AM.
Tags
None
Referenced Files
F31495974: raw.txt
Jan 1 2020, 3:52 AM
Subscribers
var data = ...; // your data here
var surfaceModel = ve.init.target.getSurface().getModel();
var referenceModel = new ve.dm.MWReferenceModel( surfaceModel.getDocument() );
// Prepare and insert an empty reference
referenceModel.insertInternalItem( surfaceModel );
referenceModel.insertReferenceNode( surfaceModel.getFragment().collapseToEnd() );
// Find the contents of the reference inside the internal list
var refContentsFragment = surfaceModel.getFragment(
// Note: this assumes that the new reference contains an empty paragraph,
// which should always be true
new ve.dm.LinearSelection( referenceModel.findInternalItem( surfaceModel ).getChildren()[ 0 ].getRange() )
);
// Insert new contents
refContentsFragment.insertContent( data );

Event Timeline

matmarex updated the paste's language from autodetect to js.

When trying to implement this code segment I get the error

TypeError: ve.dm.MWReferenceModel is not a constructor

I guess I am missing out something.

ve.dm.MWReferenceModel is defined in the Cite extension, make sure it's installed?