Skip to content

Instantly share code, notes, and snippets.

@catrope
Created July 22, 2014 21:17
Show Gist options
  • Save catrope/dfe1daa1d586efa431ed to your computer and use it in GitHub Desktop.
Save catrope/dfe1daa1d586efa431ed to your computer and use it in GitHub Desktop.
Insert <h2>Hello</h2> at the beginning
var html = '<h2>Hello</h2>',
htmlDoc = ve.createDocumentFromHTML( html ),
newDmDoc = ve.dm.converter.getModelFromDom( htmlDoc ), // Omitting targetDoc here, which may cause issues with link hrefs
surfaceModel = ve.init.target.getSurface().getModel(),
tx = ve.dm.Transaction.newFromDocumentInsertion( surfaceModel.getDocument(), 0, newDmDoc ); // 0 means insert at the beginning
surfaceModel.change( tx );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment