+ 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 && $(el.prev()[0]).attr('wlxml-tag') === 'span',
+ hasSpanAfter = el.next().length > 0 && $(el.next()[0]).attr('wlxml-tag') === 'span';
+
+
+ var addInfo = function(toAdd) {
+ var parentContents = elParent.contents(),
+ idx = parentContents.index(el[0]),
+ next = idx < parentContents.length - 1 ? parentContents[idx+1] : null;
+ if(next) {
+ $(next).data('orig-before', toAdd);
+ } else {
+ elParent.data('orig-append', 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) ? ' ' : '');