My Javascript code follows. The PasteHTML puts the string at the beginning of the editor's content, regardless of the original position of 'selectedhtml'
var editor1 = document.getElementById('');
var editor1doc = editor1.GetDocument();
var selectedhtml = editor1doc.selection.createRange().htmlText;
editor1.PasteHTML("**BEFORESELECTION**" + selectedhtml + "**AFTERSELECTION**");