From d469f4c1933942e83c4e63f09d2afd35c781d786 Mon Sep 17 00:00:00 2001 From: Anton Mitrofanov Date: Thu, 28 Jan 2021 14:25:07 +0300 Subject: [PATCH] Fix formatting with more than 100 levels of nesting --- extension.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/extension.js b/extension.js index ff5185f..7f24763 100644 --- a/extension.js +++ b/extension.js @@ -61,6 +61,7 @@ VKBeautify.prototype.xml = function(text,step) { len = ar.length, inComment = false, inCDATA = false, + deep_real = 0, deep = 0, str = '', ix = 0, @@ -123,22 +124,25 @@ VKBeautify.prototype.xml = function(text,step) { else if( ix > 0 && /^<\/[^<>!?\/\s]/.exec(ar[ix]) && /^<[^<>!?\/\s]/.exec(ar[ix-1]) && /^<\/[^<>!?\/\s]+/.exec(ar[ix])[0].replace('/','') == /^<[^<>!?\/\s]+/.exec(ar[ix-1])[0] ) { - if(deep > 0) deep--; + if(deep_real > 0) deep_real--; + if(deep_real <= 100) deep = deep_real; str += ar[ix]; } // // else if(ar[ix].search(/<\//) > -1) { - if(deep > 0) deep--; + if(deep_real > 0) deep_real--; + if(deep_real <= 100) deep = deep_real; str = str.trim()+shift[deep]+ar[ix]; } // or // else if(ar[ix].search(/<[^<>!?\/\s]/) > -1) { str = str.trim()+shift[deep]+ar[ix]; - deep++; + deep_real++; // // if(ar[ix].search(/\/>/) > -1) { - deep--; + deep_real--; } + if(deep_real <= 100) deep = deep_real; } // xmlns // //else if(ar[ix].search(/xmlns[:=]/) > -1) {