From cef69fff5322bdc7766d7063809694f6ee0e9e47 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Mon, 30 Jun 2014 14:47:57 +0200 Subject: [PATCH 1/1] smartxml: additional text nodes merge strategies for ElementNode.detach --- src/smartxml/core.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/smartxml/core.js b/src/smartxml/core.js index 7118584..b40e9c3 100644 --- a/src/smartxml/core.js +++ b/src/smartxml/core.js @@ -120,12 +120,24 @@ var documentNodeTransformations = { var elementNodeTransformations = { - detach: function() { + detach: function(params) { var next; + params = _.extend({ + normalizeStrategy: 'merge' + }, params); + if(this.parent() && this.isSurroundedByTextNodes()) { - next = this.next(); - this.prev().appendText(next.getText()); - next.detach(); + if(params.normalizeStrategy === 'detach-left') { + this.prev().detach(); + } else if(params.normalizeStrategy === 'detach-right') { + this.next().detach(); + } else if(params.normalizeStrategy === 'merge') { + next = this.next(); + this.prev().appendText(next.getText()); + next.detach(); + } else { + throw new Error('unknown normalize strategy for detach'); + } } return this.__super__.detach(); }, -- 2.20.1