+ var el = $(this),
+ text = {original: el.text(), trimmed: $.trim(el.text())},
+ elParent = el.parent(),
+ hasSpanParent = elParent.attr('wlxml-tag') === 'span',
+ hasSpanBefore = el.prev().length > 0 && getNode($(el.prev()[0])).attr('wlxml-tag') === 'span',
+ hasSpanAfter = el.next().length > 0 && getNode($(el.next()[0])).attr('wlxml-tag') === 'span';
+
+ if(el.parent().hasClass('canvas-widget'))
+ return true; // continue
+
+ var addInfo = function(toAdd, where) {
+ var parentContents = elParent.contents(),
+ idx = parentContents.index(el[0]),
+ prev = idx > FIRST_CONTENT_INDEX ? parentContents[idx-1] : null,
+ next = idx < parentContents.length - 1 ? parentContents[idx+1] : null,
+ target, key;
+
+ if(where === 'above') {
+ target = prev ? $(prev) : elParent.parent();
+ key = prev ? 'orig-after' : 'orig-begin';
+ } else if(where === 'below') {
+ target = next ? $(next) : elParent.parent();
+ key = next ? 'orig-before' : 'orig-end';
+ } else { throw new Object;}
+
+ target.data(key, toAdd);
+ }
+
+ text.transformed = text.trimmed;
+
+ if(hasSpanParent || hasSpanBefore || hasSpanAfter) {
+ var startSpace = /\s/g.test(text.original.substr(0,1)),
+ endSpace = /\s/g.test(text.original.substr(-1)) && text.original.length > 1;
+ text.transformed = (startSpace && (hasSpanParent || hasSpanBefore) ? ' ' : '')
+ + text.trimmed
+ + (endSpace && (hasSpanParent || hasSpanAfter) ? ' ' : '');