From 0b878f131dd0cb955cd50077acec4a440cd1216f Mon Sep 17 00:00:00 2001 From: bbpennel Date: Mon, 1 Jul 2013 13:11:09 -0400 Subject: [PATCH 1/2] Keeping closing tags on same line as element text when there is a namespace on the tag --- vkbeautify.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/vkbeautify.js b/vkbeautify.js index 13cee3a..a418e6d 100644 --- a/vkbeautify.js +++ b/vkbeautify.js @@ -94,7 +94,8 @@ vkbeautify.prototype.xml = function(text,step) { deep = 0, str = '', ix = 0, - shift = step ? createShiftArr(step) : this.shift; + shift = step ? createShiftArr(step) : this.shift, + withNamespace = false; for(ix=0;ix or // if(ar[ix].search(/<\//) > -1) { - str = !inComment ? str += shift[--deep]+ar[ix] : str += ar[ix]; + --deep; + str = !inComment && !withNamespace? str += shift[deep] + ar[ix] : str += ar[ix]; + withNamespace = false; } else // // if(ar[ix].search(/\/>/) > -1 ) { @@ -140,6 +143,7 @@ vkbeautify.prototype.xml = function(text,step) { // xmlns // if( ar[ix].search(/xmlns\:/) > -1 || ar[ix].search(/xmlns\=/) > -1) { str += shift[deep]+ar[ix]; + withNamespace = true; } else { From 7107a6204739d8007599c09a7da0768cd26daaec Mon Sep 17 00:00:00 2001 From: bbpennel Date: Tue, 2 Jul 2013 10:17:25 -0400 Subject: [PATCH 2/2] Fixing runaway indenting when siblings have namespaces specified --- vkbeautify.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/vkbeautify.js b/vkbeautify.js index a418e6d..dfc2bab 100644 --- a/vkbeautify.js +++ b/vkbeautify.js @@ -95,7 +95,7 @@ vkbeautify.prototype.xml = function(text,step) { str = '', ix = 0, shift = step ? createShiftArr(step) : this.shift, - withNamespace = false; + withNamespace = 0; for(ix=0;ix or -1) { --deep; str = !inComment && !withNamespace? str += shift[deep] + ar[ix] : str += ar[ix]; - withNamespace = false; } else // // if(ar[ix].search(/\/>/) > -1 ) { str = !inComment ? str += shift[deep]+ar[ix] : str += ar[ix]; + if (ar[ix].search(/xmlns\:/) > -1 || ar[ix].search(/xmlns\=/) > -1) + deep--; } else // // if(ar[ix].search(/<\?/) > -1) { @@ -143,12 +144,14 @@ vkbeautify.prototype.xml = function(text,step) { // xmlns // if( ar[ix].search(/xmlns\:/) > -1 || ar[ix].search(/xmlns\=/) > -1) { str += shift[deep]+ar[ix]; - withNamespace = true; + withNamespace = 2; } else { str += ar[ix]; } + if (withNamespace) + withNamespace--; } return (str[0] == '\n') ? str.slice(1) : str;