+ },
+
+ _wrapText: function(params) {
+ params = _.extend({textNodeIdx: 0}, params);
+ if(typeof params.textNodeIdx === 'number') {
+ params.textNodeIdx = [params.textNodeIdx];
+ }
+
+ var contentsInside = params.inside.contents(),
+ idx1 = Math.min.apply(Math, params.textNodeIdx),
+ idx2 = Math.max.apply(Math, params.textNodeIdx),
+ textNode1 = contentsInside[idx1],
+ textNode2 = contentsInside[idx2],
+ sameNode = textNode1.sameNode(textNode2),
+ prefixOutside = textNode1.getText().substr(0, params.offsetStart),
+ prefixInside = textNode1.getText().substr(params.offsetStart),
+ suffixInside = textNode2.getText().substr(0, params.offsetEnd),
+ suffixOutside = textNode2.getText().substr(params.offsetEnd)
+ ;
+
+ var wrapperElement = this.createElementNode({tagName: params._with.tag, attrs: params._with.attrs});
+ textNode1.after(wrapperElement);
+ textNode1.detach();
+
+ if(prefixOutside.length > 0) {
+ wrapperElement.before({text:prefixOutside});
+ }
+ if(sameNode) {
+ var core = textNode1.getText().substr(params.offsetStart, params.offsetEnd - params.offsetStart);
+ wrapperElement.append({text: core});
+ } else {
+ textNode2.detach();
+ if(prefixInside.length > 0) {
+ wrapperElement.append({text: prefixInside});
+ }
+ for(var i = idx1 + 1; i < idx2; i++) {
+ wrapperElement.append(contentsInside[i]);
+ }
+ if(suffixInside.length > 0) {
+ wrapperElement.append({text: suffixInside});
+ }
+ }
+ if(suffixOutside.length > 0) {
+ wrapperElement.after({text: suffixOutside});
+ }
+ return wrapperElement;