From 558366adf4699a40597ba130e6e04e36ec8b29ed Mon Sep 17 00:00:00 2001 From: Austin Cheney Date: Tue, 16 Aug 2016 07:37:54 -0500 Subject: [PATCH] bug fixes --- .bower.json | 2 +- .prettydiffrc | 47 +- api/dom.js | 7 +- api/node-local.js | 59 +- bower.json | 2 +- lib/csspretty.js | 3825 +++++++-------- lib/csvpretty.js | 172 +- lib/diffview.js | 2143 ++++----- lib/finalFile.js | 2738 +++++------ lib/jspretty.js | 10636 +++++++++++++++++++++--------------------- lib/language.js | 484 +- lib/markuppretty.js | 7180 ++++++++++++++-------------- lib/options.js | 78 +- lib/safeSort.js | 349 +- package.json | 2 +- prettydiff.js | 705 ++- test/lint.js | 253 +- 17 files changed, 14364 insertions(+), 14318 deletions(-) diff --git a/.bower.json b/.bower.json index b914f5c7..24b2ae46 100644 --- a/.bower.json +++ b/.bower.json @@ -1,6 +1,6 @@ { "name" : "prettydiff", - "version" : "2.1.3", + "version" : "2.1.4", "description" : "Pretty Diff can minify, beautify (pretty print), or diff code to normalize white space and comments so that only code is being compared.", "keywords" : [ "pretty diff", "minify", "beautify", "pretty print", "white space", "whitespace", "diff", "compare", "html", "javascript", "xml", "json", "css", "less", "scss", "scope", "analysis", "node", "nodejs", "wsh" diff --git a/.prettydiffrc b/.prettydiffrc index aa9c5ee0..83565efd 100644 --- a/.prettydiffrc +++ b/.prettydiffrc @@ -9,9 +9,10 @@ //if (option.mode === "beautify" || option.lang === "auto") { // option.wrap = 120; //} -global.prettydiff.prettydiffrc = function (option) { +(function prettydiffrc_init() { "use strict"; - // edit below this line + var prettydiffrc = function prettydiffrc(option) { + // edit below this line @@ -19,24 +20,26 @@ global.prettydiff.prettydiffrc = function (option) { - // edit above this line - return option; -}; + // edit above this line + return option; + }; -if (typeof module === "object" && typeof module.parent === "object") { - //commonjs and nodejs support - module.exports = global.prettydiff.prettydiffrc; -} else if ((typeof define === "object" || typeof define === "function") && (typeof ace !== "object" || ace.prettydiffid === undefined)) { - //requirejs support - define(function requirejs(require, module) { - "use strict"; - module.exports = global.prettydiffrc.preset; - //worthless if block to appease RequireJS and JSLint - if (typeof require === "number") { - return require; - } - return function requirejs_prettydiffrc_module(x) { - global.prettydiff.prettydiffrc(x); - }; - }); -} + if (typeof module === "object" && typeof module.parent === "object") { + //commonjs and nodejs support + module.exports = prettydiffrc; + } else if ((typeof define === "object" || typeof define === "function") && (typeof ace !== "object" || ace.prettydiffid === undefined)) { + //requirejs support + define(function requirejs(require, module) { + module.exports = prettydiffrc; + //worthless if block to appease RequireJS and JSLint + if (typeof require === "number") { + return require; + } + return function requirejs_prettydiffrc_module(x) { + prettydiffrc(x); + }; + }); + } else { + global.prettydiff.prettydiffrc = prettydiffrc; + } +}()); diff --git a/api/dom.js b/api/dom.js index d6b65494..3be7514e 100755 --- a/api/dom.js +++ b/api/dom.js @@ -841,7 +841,7 @@ global.prettydiff.meta = { if (item.nodeName.toLowerCase() === "select") { node = item[item.selectedIndex].value; } else { - node = node.value; + node = item.value; } pd.data.commentString = global.prettydiff.options.functions.domops(id, node, pd.data.commentString); if (pd.data.node.comment !== null) { @@ -6440,11 +6440,6 @@ global.prettydiff.meta = { if (pd.data.node.comment !== null) { if (pd.data.commentString.length === 0) { pd.data.node.comment.innerHTML = "/*prettydiff.com */"; - } else if (pd.data.commentString.length === 1) { - pd.data.node.comment.innerHTML = "/*prettydiff.com " + pd - .data - .commentString[0] - .replace("api.", "") + " */"; } else { pd.data.node.comment.innerHTML = "/*prettydiff.com " + pd .data diff --git a/api/node-local.js b/api/node-local.js index a3ea64c3..74b6df9d 100644 --- a/api/node-local.js +++ b/api/node-local.js @@ -44,26 +44,12 @@ Examples: cwd = (process.cwd() === "/") ? __dirname : process.cwd(), - libs = (function pdNodeLocal__libs() { - global.prettydiff = {}; - global.prettydiff.language = require(localPath + "lib/language.js"); - global.prettydiff.safeSort = require(localPath + "lib/safeSort.js"); - global.prettydiff.options = require(localPath + "lib/options.js"); - global.prettydiff.csspretty = require(localPath + "lib/csspretty.js"); - global.prettydiff.csvpretty = require(localPath + "lib/csvpretty.js"); - global.prettydiff.diffview = require(localPath + "lib/diffview.js"); - global.prettydiff.finalFile = require(localPath + "lib/finalFile.js"); - global.prettydiff.jspretty = require(localPath + "lib/jspretty.js"); - global.prettydiff.markuppretty = require(localPath + "lib/markuppretty.js"); - return localPath; - }()), - options = global.prettydiff.options, + options = {}, diffCount = [ 0, 0, 0, 0, 0 ], method = "auto", langauto = false, - pdapp = require(libs + "prettydiff.js"), prettydiff = function pdNodeLocal__prettydiff() { var lang = (function pdNodeLocal__prettydiff_lang() { if (langauto === true) { @@ -71,7 +57,7 @@ Examples: } return options.lang; }()), - pdresponse = pdapp(options), + pdresponse = global.prettydiff.prettydiff(options), data = (options.nodeasync === true) ? (options.mode === "parse" && method !== "screen" && method !== "filescreen" && options.parseFormat !== "htmltable") ? JSON.stringify(pdresponse[0]) @@ -130,7 +116,6 @@ Examples: ], lf = "\n", startTime = Date.now(), - versionString = options.functions.versionString(), dir = [ 0, 0, 0 ], @@ -548,7 +533,7 @@ Examples: options.diff = dfiledump[data.index]; options.source = sfiledump[data.index]; screenWrite(); - } else if (method === "file" || method === "directory" || method === "subdirectory") { + } else if (method === "file" || method === "directory" || method === "subdirectory") {if(method === "subdirectory") fileWrite(data); } sState[data.index] = false; @@ -905,6 +890,19 @@ Examples: } }; + global.prettydiff = {}; + global.prettydiff.language = require(localPath + "lib/language.js"); + global.prettydiff.safeSort = require(localPath + "lib/safeSort.js"); + global.prettydiff.options = require(localPath + "lib/options.js"); + global.prettydiff.csspretty = require(localPath + "lib/csspretty.js"); + global.prettydiff.csvpretty = require(localPath + "lib/csvpretty.js"); + global.prettydiff.diffview = require(localPath + "lib/diffview.js"); + global.prettydiff.finalFile = require(localPath + "lib/finalFile.js"); + global.prettydiff.jspretty = require(localPath + "lib/jspretty.js"); + global.prettydiff.markuppretty = require(localPath + "lib/markuppretty.js"); + global.prettydiff.prettydiff = require(localPath + "prettydiff.js"); + options = global.prettydiff.options; + //defaults for the options (function pdNodeLocal__start() { var argument = process @@ -1025,6 +1023,23 @@ Examples: odirs = address .oorgpath .split(path.sep); + if (odirs[0] === "..") { + (function pdNodeLocal__start_pathslash_stat() { + var abs = path.resolve().split(path.sep), + a = 0; + do { + a += 1; + } while (odirs[a] === ".."); + odirs.splice(0, a); + abs.splice(0, a); + do { + odirs.splice(0, 0, abs.pop()); + } while (abs.length > 0); + if (path.sep === "/") { + odirs.splice(0, 0, ""); + } + }()); + } if (options.readmethod === "file") { odirs.pop(); } @@ -1215,10 +1230,6 @@ Examples: if (alphasort === true) { options.objsort = "all"; } - if (options.lang === "tss") { - options.titanium = true; - options.lang = "javascript"; - } if (options.mode !== "diff") { options.diffcli = false; options.summaryonly = false; @@ -1231,7 +1242,7 @@ Examples: return console.log(options.functions.consolePrint()); } if (help === true && options.version === true) { - return console.log(versionString); + return console.log(options.functions.versionString); } if (options.listoptions === true) { (function pdNodeLocal__start_stat_init_listoptions() { @@ -1242,7 +1253,7 @@ Examples: options.mode = "beautify"; options.source = sample; options.vertical = "all"; - sample = pdapp(options); + sample = global.prettydiff.prettydiff(options); console.log(""); console.log(colors.filepath.start + "Current option settings:" + colors.filepath.end); console.log(sample.slice(1, sample.length - 1)); diff --git a/bower.json b/bower.json index 326a5d64..b294d3f2 100644 --- a/bower.json +++ b/bower.json @@ -36,5 +36,5 @@ ], "main": "./", "name": "prettydiff", - "version": "2.1.3" + "version": "2.1.4" } diff --git a/lib/csspretty.js b/lib/csspretty.js index aed32e1d..7c58f67b 100644 --- a/lib/csspretty.js +++ b/lib/csspretty.js @@ -20,824 +20,755 @@ analysis of the code. ----------------------------------------------------------------------- */ -global.prettydiff.csspretty = function csspretty_(options) { +(function () { "use strict"; - var token = [], - types = [], - lines = [], - depth = [], - begin = [], - uri = [], - colors = [], - output = "", - endline = false, - objsortop = false, - verticalop = false, - colorNames = { - aliceblue : 0.9288006825347457, - antiquewhite : 0.8464695170775405, - aqua : 0.7874, - aquamarine : 0.8078549208338043, - azure : 0.9726526495416643, - beige : 0.8988459998705021, - bisque : 0.8073232737297876, - black : 0, - blanchedalmond : 0.8508443960815607, - blue : 0.0722, - blueviolet : 0.12622014321946043, - brown : 0.09822428787651079, - burlywood : 0.5155984453389335, - cadetblue : 0.29424681085422044, - chartreuse : 0.7603202590262282, - chocolate : 0.23898526114557292, - coral : 0.3701793087292368, - cornflowerblue : 0.30318641994179363, - cornsilk : 0.9356211037296492, - crimson : 0.16042199953025577, - cyan : 0.7874, - darkblue : 0.018640801980939217, - darkcyan : 0.2032931783904645, - darkgoldenrod : 0.27264703559992554, - darkgray : 0.39675523072562674, - darkgreen : 0.09114342904757505, - darkgrey : 0.39675523072562674, - darkkhaki : 0.45747326349994155, - darkmagenta : 0.07353047651207048, - darkolivegreen : 0.12651920884889156, - darkorange : 0.40016167026523863, - darkorchid : 0.1341314217485677, - darkred : 0.05488967453113126, - darksalmon : 0.4054147156338075, - darkseagreen : 0.43789249325969054, - darkslateblue : 0.06579284622798763, - darkslategray : 0.06760815192804355, - darkslategrey : 0.06760815192804355, - darkturquoise : 0.4874606277449034, - darkviolet : 0.10999048339343433, - deeppink : 0.2386689582827583, - deepskyblue : 0.444816033955754, - dimgray : 0.14126329114027164, - dimgrey : 0.14126329114027164, - dodgerblue : 0.2744253699145608, - firebrick : 0.10724525535015225, - floralwhite : 0.9592248482500424, - forestgreen : 0.18920812076002244, - fuchsia : 0.2848, - gainsboro : 0.7156935005064806, - ghostwhite : 0.9431126188632283, - gold : 0.6986087742815887, - goldenrod : 0.41919977809568404, - gray : 0.21586050011389915, - green : 0.15438342968146068, - greenyellow : 0.8060947261145331, - grey : 0.21586050011389915, - honeydew : 0.9633653555478173, - hotpink : 0.3465843816971475, - indianred : 0.21406134963884, - indigo : 0.031075614863369846, - ivory : 0.9907127060061531, - khaki : 0.7701234339412052, - lavendar : 0.8031875051452125, - lavendarblush : 0.9017274863104644, - lawngreen : 0.7390589312496334, - lemonchiffon : 0.9403899224562171, - lightblue : 0.6370914128080659, - lightcoral : 0.35522120733134843, - lightcyan : 0.9458729349482863, - lightgoldenrodyellow: 0.9334835101829635, - lightgray : 0.651405637419824, - lightgreen : 0.6909197995686475, - lightgrey : 0.651405637419824, - lightpink : 0.5856615273489745, - lightsalmon : 0.47806752252059587, - lightseagreen : 0.3505014511704197, - lightskyblue : 0.5619563761833096, - lightslategray : 0.23830165007286924, - lightslategrey : 0.23830165007286924, - lightyellow : 0.9816181839288161, - lime : 0.7152, - limegreen : 0.44571042246097864, - linen : 0.8835734098437936, - magenta : 0.2848, - maroon : 0.04589194232421496, - mediumaquamarine : 0.4938970331080111, - mediumblue : 0.04407778021232784, - mediumorchid : 0.21639251153773428, - mediumpurple : 0.22905858091648004, - mediumseagreen : 0.34393112338131226, - mediumslateblue : 0.20284629471622434, - mediumspringgreen : 0.7070430819418444, - mediumturquois : 0.5133827926447991, - mediumvioletred : 0.14371899849357186, - midnightblue : 0.020717866350860484, - mintcream : 0.9783460494758793, - mistyrose : 0.8218304785918541, - moccasin : 0.8008300099156694, - navajowhite : 0.7651968234278562, - navy : 0.015585128108223519, - oldlace : 0.9190063340554899, - olive : 0.20027537200567563, - olivedrab : 0.2259315095192918, - orange : 0.48170267036309605, - orangered : 0.2551624375341641, - orchid : 0.3134880676143873, - palegoldenrod : 0.7879264788761452, - palegreen : 0.7793675900635259, - paleturquoise : 0.764360779217138, - palevioletred : 0.2875499411788909, - papayawhip : 0.8779710019983541, - peachpuff : 0.7490558987825108, - peru : 0.3011307487793569, - pink : 0.6327107070246611, - plum : 0.4573422158796909, - powderblue : 0.6825458650060524, - purple : 0.061477070432438476, - red : 0.2126, - rosyblue : 0.3231945764940708, - royalblue : 0.16663210743188323, - saddlebrown : 0.09792228502052071, - salmon : 0.3697724152759545, - sandybrown : 0.46628543696283414, - seagreen : 0.1973419970627483, - seashell : 0.927378622069223, - sienna : 0.13697631337097677, - silver : 0.527115125705813, - skyblue : 0.5529166851818412, - slateblue : 0.14784278062136097, - slategray : 0.20896704076536138, - slategrey : 0.20896704076536138, - slightsteelblue : 0.5398388828466575, - snow : 0.9653334183484877, - springgreen : 0.7305230606852947, - steelblue : 0.20562642207624846, - tan : 0.48237604163921527, - teal : 0.1699685577896842, - thistle : 0.5681840109373312, - tomato : 0.3063861271941505, - turquoise : 0.5895536427577983, - violet : 0.40315452986676303, - wheat : 0.7490970282048214, - white : 1, - whitesmoke : 0.913098651793419, - yellow : 0.9278, - yellowgreen : 0.5076295720870697 - }, - stats = { - braces : 0, - colon : 0, - comments : { - chars: 0, - count: 0 + var csspretty = function csspretty_(options) { + var token = [], + types = [], + lines = [], + depth = [], + begin = [], + uri = [], + colors = [], + output = "", + endline = false, + objsortop = false, + verticalop = false, + colorNames = { + aliceblue : 0.9288006825347457, + antiquewhite : 0.8464695170775405, + aqua : 0.7874, + aquamarine : 0.8078549208338043, + azure : 0.9726526495416643, + beige : 0.8988459998705021, + bisque : 0.8073232737297876, + black : 0, + blanchedalmond : 0.8508443960815607, + blue : 0.0722, + blueviolet : 0.12622014321946043, + brown : 0.09822428787651079, + burlywood : 0.5155984453389335, + cadetblue : 0.29424681085422044, + chartreuse : 0.7603202590262282, + chocolate : 0.23898526114557292, + coral : 0.3701793087292368, + cornflowerblue : 0.30318641994179363, + cornsilk : 0.9356211037296492, + crimson : 0.16042199953025577, + cyan : 0.7874, + darkblue : 0.018640801980939217, + darkcyan : 0.2032931783904645, + darkgoldenrod : 0.27264703559992554, + darkgray : 0.39675523072562674, + darkgreen : 0.09114342904757505, + darkgrey : 0.39675523072562674, + darkkhaki : 0.45747326349994155, + darkmagenta : 0.07353047651207048, + darkolivegreen : 0.12651920884889156, + darkorange : 0.40016167026523863, + darkorchid : 0.1341314217485677, + darkred : 0.05488967453113126, + darksalmon : 0.4054147156338075, + darkseagreen : 0.43789249325969054, + darkslateblue : 0.06579284622798763, + darkslategray : 0.06760815192804355, + darkslategrey : 0.06760815192804355, + darkturquoise : 0.4874606277449034, + darkviolet : 0.10999048339343433, + deeppink : 0.2386689582827583, + deepskyblue : 0.444816033955754, + dimgray : 0.14126329114027164, + dimgrey : 0.14126329114027164, + dodgerblue : 0.2744253699145608, + firebrick : 0.10724525535015225, + floralwhite : 0.9592248482500424, + forestgreen : 0.18920812076002244, + fuchsia : 0.2848, + gainsboro : 0.7156935005064806, + ghostwhite : 0.9431126188632283, + gold : 0.6986087742815887, + goldenrod : 0.41919977809568404, + gray : 0.21586050011389915, + green : 0.15438342968146068, + greenyellow : 0.8060947261145331, + grey : 0.21586050011389915, + honeydew : 0.9633653555478173, + hotpink : 0.3465843816971475, + indianred : 0.21406134963884, + indigo : 0.031075614863369846, + ivory : 0.9907127060061531, + khaki : 0.7701234339412052, + lavendar : 0.8031875051452125, + lavendarblush : 0.9017274863104644, + lawngreen : 0.7390589312496334, + lemonchiffon : 0.9403899224562171, + lightblue : 0.6370914128080659, + lightcoral : 0.35522120733134843, + lightcyan : 0.9458729349482863, + lightgoldenrodyellow: 0.9334835101829635, + lightgray : 0.651405637419824, + lightgreen : 0.6909197995686475, + lightgrey : 0.651405637419824, + lightpink : 0.5856615273489745, + lightsalmon : 0.47806752252059587, + lightseagreen : 0.3505014511704197, + lightskyblue : 0.5619563761833096, + lightslategray : 0.23830165007286924, + lightslategrey : 0.23830165007286924, + lightyellow : 0.9816181839288161, + lime : 0.7152, + limegreen : 0.44571042246097864, + linen : 0.8835734098437936, + magenta : 0.2848, + maroon : 0.04589194232421496, + mediumaquamarine : 0.4938970331080111, + mediumblue : 0.04407778021232784, + mediumorchid : 0.21639251153773428, + mediumpurple : 0.22905858091648004, + mediumseagreen : 0.34393112338131226, + mediumslateblue : 0.20284629471622434, + mediumspringgreen : 0.7070430819418444, + mediumturquois : 0.5133827926447991, + mediumvioletred : 0.14371899849357186, + midnightblue : 0.020717866350860484, + mintcream : 0.9783460494758793, + mistyrose : 0.8218304785918541, + moccasin : 0.8008300099156694, + navajowhite : 0.7651968234278562, + navy : 0.015585128108223519, + oldlace : 0.9190063340554899, + olive : 0.20027537200567563, + olivedrab : 0.2259315095192918, + orange : 0.48170267036309605, + orangered : 0.2551624375341641, + orchid : 0.3134880676143873, + palegoldenrod : 0.7879264788761452, + palegreen : 0.7793675900635259, + paleturquoise : 0.764360779217138, + palevioletred : 0.2875499411788909, + papayawhip : 0.8779710019983541, + peachpuff : 0.7490558987825108, + peru : 0.3011307487793569, + pink : 0.6327107070246611, + plum : 0.4573422158796909, + powderblue : 0.6825458650060524, + purple : 0.061477070432438476, + red : 0.2126, + rosyblue : 0.3231945764940708, + royalblue : 0.16663210743188323, + saddlebrown : 0.09792228502052071, + salmon : 0.3697724152759545, + sandybrown : 0.46628543696283414, + seagreen : 0.1973419970627483, + seashell : 0.927378622069223, + sienna : 0.13697631337097677, + silver : 0.527115125705813, + skyblue : 0.5529166851818412, + slateblue : 0.14784278062136097, + slategray : 0.20896704076536138, + slategrey : 0.20896704076536138, + slightsteelblue : 0.5398388828466575, + snow : 0.9653334183484877, + springgreen : 0.7305230606852947, + steelblue : 0.20562642207624846, + tan : 0.48237604163921527, + teal : 0.1699685577896842, + thistle : 0.5681840109373312, + tomato : 0.3063861271941505, + turquoise : 0.5895536427577983, + violet : 0.40315452986676303, + wheat : 0.7490970282048214, + white : 1, + whitesmoke : 0.913098651793419, + yellow : 0.9278, + yellowgreen : 0.5076295720870697 }, - properties: { - chars: 0, - count: 0 - }, - selectors : { - chars: 0, - count: 0 - }, - semi : 0, - space : 0, - values : { - chars: 0, - count: 0 + stats = { + braces : 0, + colon : 0, + comments : { + chars: 0, + count: 0 + }, + properties: { + chars: 0, + count: 0 + }, + selectors : { + chars: 0, + count: 0 + }, + semi : 0, + space : 0, + values : { + chars: 0, + count: 0 + }, + variables : { + chars: 0, + count: 0 + } }, - variables : { - chars: 0, - count: 0 + lf = (options.crlf === true || options.crlf === "true") + ? "\r\n" + : "\n"; + (function csspretty__options() { + objsortop = (options.objsort === true || options.objsort === "true" || options.objsort === "all" || options.objsort === "css"); + verticalop = (options.compressedcss === false && (options.vertical === true || options.vertical === "true" || options.vertical === "all" || options.vertical === "css")); + options.source = (typeof options.source === "string" && options.source.length > 0) + ? options + .source + .replace(/\r\n?/g, "\n") + " " + : "Error: no source code supplied to csspretty!"; + }()); + if (typeof options.source !== "string" || options.source === "" || (/^(\s+)$/).test(options.source) === true) { + if (options.nodeasync === true) { + return [options.source, "Error: no source supplied to csspretty."]; } - }, - lf = (options.crlf === true || options.crlf === "true") - ? "\r\n" - : "\n"; - (function csspretty__options() { - objsortop = (options.objsort === true || options.objsort === "true" || options.objsort === "all" || options.objsort === "css"); - verticalop = (options.compressedcss === false && (options.vertical === true || options.vertical === "true" || options.vertical === "all" || options.vertical === "css")); - options.source = (typeof options.source === "string" && options.source.length > 0) - ? options - .source - .replace(/\r\n?/g, "\n") + " " - : "Error: no source code supplied to csspretty!"; - }()); - if (typeof options.source !== "string" || options.source === "" || (/^(\s+)$/).test(options.source) === true) { - if (options.nodeasync === true) { - return [options.source, "Error: no source supplied to csspretty."]; - } - if (global.prettydiff.meta === undefined) { - global.prettydiff.meta = {}; + if (global.prettydiff.meta === undefined) { + global.prettydiff.meta = {}; + } + global.prettydiff.meta.error = options.source; + return options.source; } - global.prettydiff.meta.error = options.source; - return options.source; - } - (function csspretty__tokenize() { - var a = 0, - b = options - .source - .split(""), - len = options.source.length, - ltype = "", - itemsize = 0, - space = "", - endtest = false, - spacecol = false, - struct = [0], - mapper = [], - structval = "root", - nosort = [], - esctest = function csspretty__tokenize_esctest(xx) { - var yy = xx; - do { - xx -= 1; - } while (xx > 0 && b[xx] === "\\"); - if ((yy - xx) % 2 === 0) { - return true; - } - return false; - }, - //map location of empty lines for beautification - spacer = function csspretty__tokenize_space(end) { - var slen = space - .split(lf) - .length - 1, - value = 0; - if (token.length === 0 && slen > 0) { - slen += 1; - } - if (slen > 0 && options.preserve > 0) { - if (slen > options.preserve) { - value = options.preserve + 1; - } else { - value = slen; + (function csspretty__tokenize() { + var a = 0, + b = options + .source + .split(""), + len = options.source.length, + ltype = "", + itemsize = 0, + space = "", + endtest = false, + spacecol = false, + struct = [0], + mapper = [], + structval = "root", + nosort = [], + esctest = function csspretty__tokenize_esctest(xx) { + var yy = xx; + do { + xx -= 1; + } while (xx > 0 && b[xx] === "\\"); + if ((yy - xx) % 2 === 0) { + return true; } - } else if (space.length > 1) { - value = 1; - } else if (slen === 0 && types[types.length - 1] === "comment" && types[types.length - 2] !== "comment") { - types[types.length - 1] = "comment-inline"; - } - if (slen > 1 && end === true && options.preserve > 0) { - endline = true; - space = ""; - return value; - } - space = ""; - return value; - }, - //sort parsed properties intelligently - objSort = function csspretty__tokenize_objSort() { - var cc = 0, - dd = 0, - ee = 0, - startlen = token.length - 1, - end = startlen, - keys = [], - keylen = 0, - keyend = 0, - start = 0, - sort = function csspretty__tokenize_objSort_sort(x, y) { - var xx = x[0], - yy = y[0]; - if (types[xx] === "comment" || types[xx] === "comment-inline") { - do { - xx += 1; - } while (xx < startlen && (types[xx] === "comment" || types[xx] === "comment-inline")); - } - if (types[yy] === "comment" || types[yy] === "comment-inline") { - do { - yy += 1; - } while (yy < startlen && (types[yy] === "comment" || types[yy] === "comment-inline")); - } - if (types[xx] < types[yy]) { - return -1; - } - if (types[xx] === types[yy] && token[xx].toLowerCase() < token[yy].toLowerCase()) { - return -1; + return false; + }, + //map location of empty lines for beautification + spacer = function csspretty__tokenize_space(end) { + var slen = space + .split(lf) + .length - 1, + value = 0; + if (token.length === 0 && slen > 0) { + slen += 1; + } + if (slen > 0 && options.preserve > 0) { + if (slen > options.preserve) { + value = options.preserve + 1; + } else { + value = slen; } - return 1; - }, - semiTest = true, - pairToken = [], - pairTypes = [], - pairLines = [], - pairDepth = [], - pairBegin = []; - if (types[end] === "comment" || types[end] === "comment-inline") { - do { - end -= 1; - } while (end > 0 && (types[end] === "comment" || types[end] === "comment-inline")); - } - for (cc = startlen; cc > -1; cc -= 1) { - if (types[cc] === "end") { - dd += 1; + } else if (space.length > 1) { + value = 1; + } else if (slen === 0 && types[types.length - 1] === "comment" && types[types.length - 2] !== "comment") { + types[types.length - 1] = "comment-inline"; } - if (types[cc] === "start") { - dd -= 1; + if (slen > 1 && end === true && options.preserve > 0) { + endline = true; + space = ""; + return value; } - if (dd === 0) { - if ((types[cc] === "property" || types[cc] === "selector" || types[cc] === "propvar") && types[cc - 1] !== "property" && types[cc - 1] !== "selector") { - start = cc; - if (types[end + 1] === "comment-inline") { - end += 1; + space = ""; + return value; + }, + //sort parsed properties intelligently + objSort = function csspretty__tokenize_objSort() { + var cc = 0, + dd = 0, + ee = 0, + startlen = token.length - 1, + end = startlen, + keys = [], + keylen = 0, + keyend = 0, + start = 0, + sort = function csspretty__tokenize_objSort_sort(x, y) { + var xx = x[0], + yy = y[0]; + if (types[xx] === "comment" || types[xx] === "comment-inline") { + do { + xx += 1; + } while (xx < startlen && (types[xx] === "comment" || types[xx] === "comment-inline")); } - if (types[start - 1] === "comment") { + if (types[yy] === "comment" || types[yy] === "comment-inline") { do { - start -= 1; - } while (start > -1 && types[start - 1] === "comment"); + yy += 1; + } while (yy < startlen && (types[yy] === "comment" || types[yy] === "comment-inline")); } - keys.push([ - start, - end + 1, - false - ]); - end = start - 1; - } + if (types[xx] < types[yy]) { + return -1; + } + if (types[xx] === types[yy] && token[xx].toLowerCase() < token[yy].toLowerCase()) { + return -1; + } + return 1; + }, + semiTest = true, + pairToken = [], + pairTypes = [], + pairLines = [], + pairDepth = [], + pairBegin = []; + if (types[end] === "comment" || types[end] === "comment-inline") { + do { + end -= 1; + } while (end > 0 && (types[end] === "comment" || types[end] === "comment-inline")); } - if (dd < 0 && cc < startlen) { - if (keys.length > 1 && (types[cc - 1] === "selector" || types[cc - 1] === "propvar" || (types[cc - 2] === "propvar" && types[cc - 1] === "value") || token[cc - 1] === "=" || token[cc - 1] === ":" || token[cc - 1] === "[" || token[cc - 1] === "{" || (token[cc - 1] === "," && structval !== "map") || cc === 0)) { - if (structval === "map" && token[token.length - 1] !== ",") { - token.push(","); - types.push("semi"); - lines.push(0); - depth.push(depth[depth.length - 1]); - begin.push(begin[begin.length - 1]); - keys[0][1] += 1; + for (cc = startlen; cc > -1; cc -= 1) { + if (types[cc] === "end") { + dd += 1; + } + if (types[cc] === "start") { + dd -= 1; + } + if (dd === 0) { + if ((types[cc] === "property" || types[cc] === "selector" || types[cc] === "propvar") && types[cc - 1] !== "property" && types[cc - 1] !== "selector") { + start = cc; + if (types[end + 1] === "comment-inline") { + end += 1; + } + if (types[start - 1] === "comment") { + do { + start -= 1; + } while (start > -1 && types[start - 1] === "comment"); + } + keys.push([ + start, + end + 1, + false + ]); + end = start - 1; } - keys.sort(sort); - keylen = keys.length; - semiTest = false; - for (dd = 0; dd < keylen; dd += 1) { - keyend = keys[dd][1]; - for (ee = keys[dd][0]; ee < keyend; ee += 1) { - pairToken.push(token[ee]); - pairTypes.push(types[ee]); - pairLines.push(lines[ee]); - pairDepth.push(depth[ee]); - pairBegin.push(begin[ee]); - if ((token[ee] === ";" && structval === "block") || (token[ee] === "," && structval === "map") || token[ee] === "}") { - semiTest = true; - } else if ((structval === "block" && token[ee] !== ";") && (structval === "map" && token[ee] !== ",") && token[ee] !== "}" && types[ee] !== "comment" && types[ee] !== "comment-inline") { - semiTest = false; + } + if (dd < 0 && cc < startlen) { + if (keys.length > 1 && (types[cc - 1] === "selector" || types[cc - 1] === "propvar" || (types[cc - 2] === "propvar" && types[cc - 1] === "value") || token[cc - 1] === "=" || token[cc - 1] === ":" || token[cc - 1] === "[" || token[cc - 1] === "{" || (token[cc - 1] === "," && structval !== "map") || cc === 0)) { + if (structval === "map" && token[token.length - 1] !== ",") { + token.push(","); + types.push("semi"); + lines.push(0); + depth.push(depth[depth.length - 1]); + begin.push(begin[begin.length - 1]); + keys[0][1] += 1; + } + keys.sort(sort); + keylen = keys.length; + semiTest = false; + for (dd = 0; dd < keylen; dd += 1) { + keyend = keys[dd][1]; + for (ee = keys[dd][0]; ee < keyend; ee += 1) { + pairToken.push(token[ee]); + pairTypes.push(types[ee]); + pairLines.push(lines[ee]); + pairDepth.push(depth[ee]); + pairBegin.push(begin[ee]); + if ((token[ee] === ";" && structval === "block") || (token[ee] === "," && structval === "map") || token[ee] === "}") { + semiTest = true; + } else if ((structval === "block" && token[ee] !== ";") && (structval === "map" && token[ee] !== ",") && token[ee] !== "}" && types[ee] !== "comment" && types[ee] !== "comment-inline") { + semiTest = false; + } + } + if (semiTest === false) { + ee = pairTypes.length - 1; + if (pairTypes[ee] === "comment" || pairTypes[ee] === "comment-inline") { + do { + ee -= 1; + } while (ee > 0 && (pairTypes[ee] === "comment" || pairTypes[ee] === "comment-inline")); + } + ee += 1; + if (structval === "map") { + pairToken.splice(ee, 0, ","); + } else { + pairToken.splice(ee, 0, ";"); + } + pairTypes.splice(ee, 0, "semi"); + pairDepth.splice(ee, 0, pairDepth[ee]); + pairBegin.splice(ee, 0, pairBegin[ee]); + if (pairLines[ee - 1] > 0) { + pairLines[ee - 1] = 0; + pairLines.splice(ee, 0, 1); + } else { + pairLines.splice(ee, 0, 0); + } } } - if (semiTest === false) { - ee = pairTypes.length - 1; - if (pairTypes[ee] === "comment" || pairTypes[ee] === "comment-inline") { + ee = pairTypes.length - 1; + if (pairTypes[ee] === "comment" || pairTypes[ee] === "comment-inline") { + do { + ee -= 1; + } while (ee > 0 && (pairTypes[ee] === "comment" || pairTypes[ee] === "comment-inline")); + } + keylen = token.length - (cc + 1); + token.splice(cc + 1, keylen); + types.splice(cc + 1, keylen); + lines.splice(cc + 1, keylen); + depth.splice(cc + 1, keylen); + begin.splice(cc + 1, keylen); + token = token.concat(pairToken); + types = types.concat(pairTypes); + lines = lines.concat(pairLines); + depth = depth.concat(pairDepth); + begin = begin.concat(pairBegin); + if (structval === "map") { + cc = token.length - 1; + if (types[cc].indexOf("comment") === 0) { do { - ee -= 1; - } while (ee > 0 && (pairTypes[ee] === "comment" || pairTypes[ee] === "comment-inline")); - } - ee += 1; - if (structval === "map") { - pairToken.splice(ee, 0, ","); - } else { - pairToken.splice(ee, 0, ";"); + cc -= 1; + } while (types[cc].indexOf("comment") === 0); } - pairTypes.splice(ee, 0, "semi"); - pairDepth.splice(ee, 0, pairDepth[ee]); - pairBegin.splice(ee, 0, pairBegin[ee]); - if (pairLines[ee - 1] > 0) { - pairLines[ee - 1] = 0; - pairLines.splice(ee, 0, 1); - } else { - pairLines.splice(ee, 0, 0); + if (token[cc] === ",") { + token.splice(cc, 1); + types.splice(cc, 1); + lines.splice(cc, 1); + depth.splice(cc, 1); + begin.splice(cc, 1); } } } - ee = pairTypes.length - 1; - if (pairTypes[ee] === "comment" || pairTypes[ee] === "comment-inline") { - do { - ee -= 1; - } while (ee > 0 && (pairTypes[ee] === "comment" || pairTypes[ee] === "comment-inline")); - } - keylen = token.length - (cc + 1); - token.splice(cc + 1, keylen); - types.splice(cc + 1, keylen); - lines.splice(cc + 1, keylen); - depth.splice(cc + 1, keylen); - begin.splice(cc + 1, keylen); - token = token.concat(pairToken); - types = types.concat(pairTypes); - lines = lines.concat(pairLines); - depth = depth.concat(pairDepth); - begin = begin.concat(pairBegin); - if (structval === "map") { - cc = token.length - 1; - if (types[cc].indexOf("comment") === 0) { - do { - cc -= 1; - } while (types[cc].indexOf("comment") === 0); + return; + } + } + }, + //the generic token builder + buildtoken = function csspretty__tokenize_build() { + var aa = 0, + bb = 0, + out = [], + block = [], + outy = "", + mappy = 0, + comma = (token.length > 0 && token[token.length - 1].charAt(token[token.length - 1].length - 1) === ","), + linev = spacer(false); + //this loop accounts for grouping mechanisms + for (aa = a; aa < len; aa += 1) { + out.push(b[aa]); + if (b[aa - 1] !== "\\" || esctest(aa) === false) { + if (b[aa] === "\"" && block[block.length - 1] !== "'") { + if (block[block.length - 1] === "\"") { + block.pop(); + } else { + block.push("\""); + } + } else if (b[aa] === "'" && block[block.length - 1] !== "\"") { + if (block[block.length - 1] === "'") { + block.pop(); + } else { + block.push("'"); } - if (token[cc] === ",") { - token.splice(cc, 1); - types.splice(cc, 1); - lines.splice(cc, 1); - depth.splice(cc, 1); - begin.splice(cc, 1); + } else if (block[block.length - 1] !== "\"" && block[block.length - 1] !== "'") { + if (b[aa] === "(") { + mappy += 1; + block.push(")"); + } else if (b[aa] === "[") { + block.push("]"); + } else if (b[aa] === "#" && b[aa + 1] === "{") { + block.push("}"); + } else if (b[aa] === block[block.length - 1]) { + block.pop(); } } } - return; - } - } - }, - //the generic token builder - buildtoken = function csspretty__tokenize_build() { - var aa = 0, - bb = 0, - out = [], - block = [], - outy = "", - mappy = 0, - comma = (token.length > 0 && token[token.length - 1].charAt(token[token.length - 1].length - 1) === ","), - linev = spacer(false); - //this loop accounts for grouping mechanisms - for (aa = a; aa < len; aa += 1) { - out.push(b[aa]); - if (b[aa - 1] !== "\\" || esctest(aa) === false) { - if (b[aa] === "\"" && block[block.length - 1] !== "'") { - if (block[block.length - 1] === "\"") { - block.pop(); + if (structval === "map" && block.length === 0 && (b[aa + 1] === "," || b[aa + 1] === ")")) { + if (b[aa + 1] === ")" && token[token.length - 1] === "(") { + token.pop(); + types.pop(); + lines.pop(); + depth.pop(); + begin.pop(); + struct.pop(); + structval = depth[depth.length - 1]; + out = ["("]; + aa = a - 1; } else { - block.push("\""); + break; } - } else if (b[aa] === "'" && block[block.length - 1] !== "\"") { - if (block[block.length - 1] === "'") { - block.pop(); - } else { - block.push("'"); + } + if (b[aa + 1] === ":") { + bb = aa; + if ((/\s/).test(b[bb]) === true) { + do { + bb -= 1; + } while ((/\s/).test(b[bb]) === true); } - } else if (block[block.length - 1] !== "\"" && block[block.length - 1] !== "'") { - if (b[aa] === "(") { - mappy += 1; - block.push(")"); - } else if (b[aa] === "[") { - block.push("]"); - } else if (b[aa] === "#" && b[aa + 1] === "{") { - block.push("}"); - } else if (b[aa] === block[block.length - 1]) { - block.pop(); + outy = b + .slice(bb - 6, bb + 1) + .join(""); + if (outy.indexOf("filter") === outy.length - 6 || outy.indexOf("progid") === outy.length - 6) { + outy = "filter"; } } - } - if (structval === "map" && block.length === 0 && (b[aa + 1] === "," || b[aa + 1] === ")")) { - if (b[aa + 1] === ")" && token[token.length - 1] === "(") { - token.pop(); - types.pop(); - lines.pop(); - depth.pop(); - begin.pop(); - struct.pop(); - structval = depth[depth.length - 1]; - out = ["("]; - aa = a - 1; - } else { + if (block.length === 0 && ((b[aa + 1] === ";" && esctest(aa + 1) === false) || (b[aa + 1] === ":" && b[aa] !== ":" && b[aa + 2] !== ":" && outy !== "filter" && outy !== "progid") || b[aa + 1] === "}" || b[aa + 1] === "{" || (b[aa + 1] === "/" && (b[aa + 2] === "*" || b[aa + 2] === "/")))) { + bb = out.length - 1; + if ((/\s/).test(out[bb]) === true) { + do { + bb -= 1; + aa -= 1; + out.pop(); + } while ((/\s/).test(out[bb]) === true); + } break; } - } - if (b[aa + 1] === ":") { - bb = aa; - if ((/\s/).test(b[bb]) === true) { - do { - bb -= 1; - } while ((/\s/).test(b[bb]) === true); - } - outy = b - .slice(bb - 6, bb + 1) - .join(""); - if (outy.indexOf("filter") === outy.length - 6 || outy.indexOf("progid") === outy.length - 6) { - outy = "filter"; + if (out[0] === "@" && block.length === 0 && (b[aa + 1] === "\"" || b[aa + 2] === "'")) { + break; } } - if (block.length === 0 && ((b[aa + 1] === ";" && esctest(aa + 1) === false) || (b[aa + 1] === ":" && b[aa] !== ":" && b[aa + 2] !== ":" && outy !== "filter" && outy !== "progid") || b[aa + 1] === "}" || b[aa + 1] === "{" || (b[aa + 1] === "/" && (b[aa + 2] === "*" || b[aa + 2] === "/")))) { - bb = out.length - 1; - if ((/\s/).test(out[bb]) === true) { - do { - bb -= 1; - aa -= 1; - out.pop(); - } while ((/\s/).test(out[bb]) === true); - } - break; + a = aa; + itemsize = out.length; + if (structval === "map" && out[0] === "(") { + mapper[mapper.length - 1] -= 1; } - if (out[0] === "@" && block.length === 0 && (b[aa + 1] === "\"" || b[aa + 2] === "'")) { - break; + if (comma === true && structval !== "map" && types[types.length - 1] !== "comment" && types[types.length - 1] !== "comment-inline") { + token[token.length - 1] = token[token.length - 1] + out + .join("") + .replace(/\s+/g, " ") + .replace(/^\s/, "") + .replace(/\s$/, ""); + return; } - } - a = aa; - itemsize = out.length; - if (structval === "map" && out[0] === "(") { - mapper[mapper.length - 1] -= 1; - } - if (comma === true && structval !== "map" && types[types.length - 1] !== "comment" && types[types.length - 1] !== "comment-inline") { - token[token.length - 1] = token[token.length - 1] + out - .join("") - .replace(/\s+/g, " ") - .replace(/^\s/, "") - .replace(/\s$/, ""); - return; - } - token.push(out.join("").replace(/\s+/g, " ").replace(/^\s/, "").replace(/\s$/, "")); - begin.push(struct[struct.length - 1]); - depth.push(structval); - lines.push(linev); - if (token[token.length - 1].indexOf("extend(") === 0) { - ltype = "pseudo"; - types.push("pseudo"); - } else if ("\"'".indexOf(token[token.length - 1].charAt(0)) > -1 && types[types.length - 1] === "propvar") { - ltype = "item"; - types.push("value"); - } else if (out[0] === "@" || out[0] === "$") { - if (types[types.length - 1] === "colon" && (types[types.length - 2] === "property" || types[types.length - 2] === "propvar")) { - ltype = "value"; + token.push(out.join("").replace(/\s+/g, " ").replace(/^\s/, "").replace(/\s$/, "")); + begin.push(struct[struct.length - 1]); + depth.push(structval); + lines.push(linev); + if (token[token.length - 1].indexOf("extend(") === 0) { + ltype = "pseudo"; + types.push("pseudo"); + } else if ("\"'".indexOf(token[token.length - 1].charAt(0)) > -1 && types[types.length - 1] === "propvar") { + ltype = "item"; types.push("value"); + } else if (out[0] === "@" || out[0] === "$") { + if (types[types.length - 1] === "colon" && (types[types.length - 2] === "property" || types[types.length - 2] === "propvar")) { + ltype = "value"; + types.push("value"); + } else { + ltype = "propvar"; + types.push("propvar"); + } } else { - ltype = "propvar"; - types.push("propvar"); + ltype = "item"; + types.push("item"); } - } else { - ltype = "item"; - types.push("item"); - } - }, - // Some tokens receive a generic type named 'item' because their type is unknown - // until we know the following syntax. This function replaces the type 'item' - // with something more specific. - item = function csspretty__tokenize_item(type) { - var aa = types.length, - bb = 0, - coms = [], - tokel = (token.length > 1) - ? token[token.length - 2] - : "", - toked = tokel.slice(tokel.length - 2), - // Since I am already identifying value types this is a good place to do some - // quick analysis and clean up on certain value conditions. These things are - // being corrected: - // * fractional values missing a leading 0 are provided a leading 0 - // * 0 values with a dimension indicator (px, em) have the dimension - // indicator removed - // * eliminate unnecessary leading 0s - // * url values that are not quoted are wrapped in double quote characters - // * color values are set to lowercase and reduced from 6 to 3 digits if - // appropriate - value = function csspretty__tokenize_item_value(val, font) { - var x = val.split(""), - leng = x.length, - cc = 0, - dd = 0, - items = [], - block = "", - values = [], - qchar = "", - qreg = {}, - colorPush = function csspretty__tokenize_item_value_colorPush(value) { - var vl = value.toLowerCase(); - if ((/^(#[0-9a-f]{3,6})$/).test(vl) === true) { - colors.push(value); - } else if ((/^(rgba?\()/).test(vl) === true) { - colors.push(value); - } else if (colorNames[vl] !== undefined) { - colors.push(value); - } - return value; - }; - if (options.quoteConvert === "double") { - qchar = "\""; - } else if (options.quoteConvert === "single") { - qchar = "'"; - } - // this loop identifies containment so that tokens/sub-tokens are correctly taken - for (cc = 0; cc < leng; cc += 1) { - items.push(x[cc]); - if (block === "") { - if (x[cc] === "\"") { - block = "\""; - dd += 1; - } else if (x[cc] === "'") { - block = "'"; - dd += 1; - } else if (x[cc] === "(") { - block = ")"; - dd += 1; - } else if (x[cc] === "[") { - block = "]"; - dd += 1; - } - } else if ((x[cc] === "(" && block === ")") || (x[cc] === "[" && block === "]")) { - dd += 1; - } else if (x[cc] === block) { - dd -= 1; - if (dd === 0) { - block = ""; - } - } - if (block === "" && x[cc] === " ") { - items.pop(); - values.push(colorPush(items.join(""))); - items = []; - } - } - values.push(colorPush(items.join(""))); - leng = values.length; - //This is where the rules mentioned above are applied - for (cc = 0; cc < leng; cc += 1) { - if (options.noleadzero === false && (/^(\.\d)/).test(values[cc]) === true) { - values[cc] = "0" + values[cc]; - } else if (options.noleadzero === true && (/^(0+\.)/).test(values[cc])) { - values[cc] = values[cc].replace(/^(0+\.)/, "."); - } else if ((/^(0+([a-z]{2,3}|%))$/).test(values[cc]) === true) { - values[cc] = "0"; - } else if ((/^(0+)/).test(values[cc]) === true) { - values[cc] = values[cc].replace(/0+/, "0"); - if ((/\d/).test(values[cc].charAt(1)) === true) { - values[cc] = values[cc].substr(1); - } - } else if ((/^url\((?!\$)/).test(values[cc]) === true && values[cc].charAt(values[cc].length - 1) === ")") { - block = values[cc].charAt(values[cc].indexOf("url(") + 4); - if (block !== "@" && block !== "{" && block !== "<" && block !== "\"" && block !== "'") { - if (qchar === "") { - values[cc] = values[cc] - .replace(/url\(\s*('|")?/, "url(\"") - .replace(/(('|")?\s*\))$/, "\")"); - } else { - values[cc] = values[cc] - .replace(/url\(\s*('|")?/, "url(" + qchar) - .replace(/(('|")?\s*\))$/, qchar + ")"); + }, + // Some tokens receive a generic type named 'item' because their type is unknown + // until we know the following syntax. This function replaces the type 'item' + // with something more specific. + item = function csspretty__tokenize_item(type) { + var aa = types.length, + bb = 0, + coms = [], + tokel = (token.length > 1) + ? token[token.length - 2] + : "", + toked = tokel.slice(tokel.length - 2), + // Since I am already identifying value types this is a good place to do some + // quick analysis and clean up on certain value conditions. These things are + // being corrected: + // * fractional values missing a leading 0 are provided a leading 0 + // * 0 values with a dimension indicator (px, em) have the dimension + // indicator removed + // * eliminate unnecessary leading 0s + // * url values that are not quoted are wrapped in double quote characters + // * color values are set to lowercase and reduced from 6 to 3 digits if + // appropriate + value = function csspretty__tokenize_item_value(val, font) { + var x = val.split(""), + leng = x.length, + cc = 0, + dd = 0, + items = [], + block = "", + values = [], + qchar = "", + qreg = {}, + colorPush = function csspretty__tokenize_item_value_colorPush(value) { + var vl = value.toLowerCase(); + if ((/^(#[0-9a-f]{3,6})$/).test(vl) === true) { + colors.push(value); + } else if ((/^(rgba?\()/).test(vl) === true) { + colors.push(value); + } else if (colorNames[vl] !== undefined) { + colors.push(value); } - } - } else if (font === true) { - if (qchar === "'") { - values[cc] = values[cc].replace(/"/g, "'"); - } else { - values[cc] = values[cc].replace(/'/g, "\""); - } - } else if (font === false && qchar !== "" && ((qchar === "\"" && values[cc].charAt(0) === "'" && values[cc].charAt(values[cc].length - 1) === "'") || (qchar === "'" && values[cc].charAt(0) === "\"" && values[cc].charAt(values[cc].length - 1) === "\""))) { - qreg = new RegExp(qchar, "g"); - values[cc] = qchar + values[cc] - .slice(1, values[cc].length - 1) - .replace(qreg, "\\" + qchar) + qchar; + return value; + }; + if (options.quoteConvert === "double") { + qchar = "\""; + } else if (options.quoteConvert === "single") { + qchar = "'"; } - } - return values.join(" "); - }; - //backtrack through immediately prior comments to find the correct token - if (ltype === "comment" || ltype === "comment-inline") { - do { - aa -= 1; - ltype = types[aa]; - coms.push(token[aa]); - } while (aa > 0 && (ltype === "comment" || ltype === "comment-inline")); - } else { - aa -= 1; - } - //if the last non-comment type is 'item' then id it - if (ltype === "item" && types[aa].indexOf("external") < 0) { - if (type === "start") { - stats.selectors.count += 1; - stats.selectors.chars += itemsize; - if (types[aa - 1] !== "comment" && types[aa - 1] !== "comment-inline" && types[aa - 1] !== "end" && types[aa - 1] !== "start" && types[aa - 1] !== "semi" && types[aa - 1] !== undefined && types[aa - 1].indexOf("external") < 0) { - (function csspretty__tokenize_item_selparts() { - var parts = [], - cc = aa, - dd = 0; - do { - parts.push(token[cc]); - if (spacecol === true && token[cc] === ":" && token[cc - 1] !== ":") { - parts.push(" "); + // this loop identifies containment so that tokens/sub-tokens are correctly taken + for (cc = 0; cc < leng; cc += 1) { + items.push(x[cc]); + if (block === "") { + if (x[cc] === "\"") { + block = "\""; + dd += 1; + } else if (x[cc] === "'") { + block = "'"; + dd += 1; + } else if (x[cc] === "(") { + block = ")"; + dd += 1; + } else if (x[cc] === "[") { + block = "]"; + dd += 1; + } + } else if ((x[cc] === "(" && block === ")") || (x[cc] === "[" && block === "]")) { + dd += 1; + } else if (x[cc] === block) { + dd -= 1; + if (dd === 0) { + block = ""; } - cc -= 1; - } while (cc > -1 && types[cc] !== "comment" && types[cc] !== "comment-inline" && types[cc] !== "end" && types[cc] !== "start" && types[cc] !== "semi" && types[cc] !== undefined); - parts.reverse(); - cc += 1; - dd = aa - cc; - token.splice(cc, dd); - types.splice(cc, dd); - lines.splice(cc, dd); - depth.splice(cc, dd); - begin.splice(cc, dd); - aa -= dd; - token[aa] = parts - .join(" ") - .replace(/(\ *:\ )/g, ":") - .replace(/(\s*,\s*)/g, ","); - }()); - } else { - token[aa] = token[aa].replace(/(\s*,\s*)/g, ","); - } - if (options.compressedcss === true) { - token[aa] = token[aa] - .replace(/\s*&/, " &") - .replace(/(\s*:\s*)/, ":") - .replace(/(\s*>\s*)/g, ">") - .replace(/^(\s+)/, "") - .replace(/(\s+)$/, ""); - } else { - token[aa] = token[aa] - .replace(/\s*&/, " &") - .replace(/(\s*:\s*)/, ":") - .replace(/(\s*>\s*)/g, " > ") - .replace(/^(\s+)/, "") - .replace(/(\s+)$/, ""); - } - (function csspretty__tokenize_item_selectorsort() { - var y = 0, - slen = token[aa].length, - z = "", - mark = 0, - list = []; - for (y = 0; y < slen; y += 1) { - if (z === "" && token[aa].charAt(y) === ",") { - list.push(token[aa].slice(mark, y)); - mark = y + 1; - } else if (token[aa].charAt(y) === "\"" || token[aa].charAt(y) === "'" || token[aa].charAt(y) === "(" || token[aa].charAt(y) === "{") { - z = token[aa].charAt(y); - } else if (token[aa].charAt(y) === z && (z === "\"" || z === "''")) { - z = ""; - } else if (token[aa].charAt(y) === ")" && z === "(") { - z = ""; - } else if (token[aa].charAt(y) === "}" && z === "{") { - z = ""; + } + if (block === "" && x[cc] === " ") { + items.pop(); + values.push(colorPush(items.join(""))); + items = []; } } - list.push(token[aa].slice(mark, y)); - list.sort(); - token[aa] = list.join(","); - }()); - types[aa] = "selector"; - ltype = "selector"; - } else if (type === "end") { - types[aa] = "value"; - ltype = "value"; - if (options.mode !== "diff") { - token[aa] = token[aa].replace(/\s*!\s+important/, " !important"); - if (options.quoteConvert !== "none" && (token[aa - 2] === "font" || token[aa - 2] === "font-family")) { - token[aa] = value(token[aa], true); - } else { - token[aa] = value(token[aa], false); - } - } - //take comments out until the 'item' is found and then put the comments back - if (options.mode === "beautify" || options.mode === "parse" || (options.mode === "diff" && options.diffcomments === true)) { - if (token[token.length - 2] === "{") { - types[types.length - 1] = "propvar"; - stats.values.count -= 1; - stats.values.chars -= itemsize; - stats.variables.count += 1; - stats.variables.chars += itemsize; - } else if (structval === "block") { - if (coms.length > 0 && ltype !== "semi" && ltype !== "end" && ltype !== "start") { - aa = coms.length - 1; - do { - token.pop(); - types.pop(); - lines.pop(); - depth.pop(); - begin.pop(); - aa -= 1; - } while (aa > 0); - if (options.mode === "diff") { - token.push("x;"); - } else { - token.push(";"); + values.push(colorPush(items.join(""))); + leng = values.length; + //This is where the rules mentioned above are applied + for (cc = 0; cc < leng; cc += 1) { + if (options.noleadzero === false && (/^(\.\d)/).test(values[cc]) === true) { + values[cc] = "0" + values[cc]; + } else if (options.noleadzero === true && (/^(0+\.)/).test(values[cc])) { + values[cc] = values[cc].replace(/^(0+\.)/, "."); + } else if ((/^(0+([a-z]{2,3}|%))$/).test(values[cc]) === true) { + values[cc] = "0"; + } else if ((/^(0+)/).test(values[cc]) === true) { + values[cc] = values[cc].replace(/0+/, "0"); + if ((/\d/).test(values[cc].charAt(1)) === true) { + values[cc] = values[cc].substr(1); } - depth.push(structval); - begin.push(struct[struct.length - 1]); - types.push("semi"); - lines.push(spacer(false)); - bb = coms.length - 1; - do { - token.push(coms[aa]); - if (coms[aa].indexOf("//") === 0 && lines[lines.length - 1] === 0) { - types.push("comment-inline"); + } else if ((/^url\((?!\$)/).test(values[cc]) === true && values[cc].charAt(values[cc].length - 1) === ")") { + block = values[cc].charAt(values[cc].indexOf("url(") + 4); + if (block !== "@" && block !== "{" && block !== "<" && block !== "\"" && block !== "'") { + if (qchar === "") { + values[cc] = values[cc] + .replace(/url\(\s*('|")?/, "url(\"") + .replace(/(('|")?\s*\))$/, "\")"); } else { - types.push("comment"); + values[cc] = values[cc] + .replace(/url\(\s*('|")?/, "url(" + qchar) + .replace(/(('|")?\s*\))$/, qchar + ")"); } - depth.push(structval); - begin.push(struct[struct.length - 1]); - lines.push(0); - aa += 1; - } while (aa < bb); - } else { - if (options.mode === "diff") { - token.push("x;"); + } + } else if (font === true) { + if (qchar === "'") { + values[cc] = values[cc].replace(/"/g, "'"); } else { - token.push(";"); + values[cc] = values[cc].replace(/'/g, "\""); } - depth.push(structval); - begin.push(struct[struct.length - 1]); - types.push("semi"); - lines.push(spacer(false)); + } else if (font === false && qchar !== "" && ((qchar === "\"" && values[cc].charAt(0) === "'" && values[cc].charAt(values[cc].length - 1) === "'") || (qchar === "'" && values[cc].charAt(0) === "\"" && values[cc].charAt(values[cc].length - 1) === "\""))) { + qreg = new RegExp(qchar, "g"); + values[cc] = qchar + values[cc] + .slice(1, values[cc].length - 1) + .replace(qreg, "\\" + qchar) + qchar; } } - } - stats.values.count += 1; - stats.values.chars += itemsize; - } else if (type === "semi") { - if (types[aa - 1] === "colon") { - stats.values.count += 1; - stats.values.chars += itemsize; - types[aa] = "value"; - ltype = "value"; + return values.join(" "); + }; + //backtrack through immediately prior comments to find the correct token + if (ltype === "comment" || ltype === "comment-inline") { + do { + aa -= 1; + ltype = types[aa]; + coms.push(token[aa]); + } while (aa > 0 && (ltype === "comment" || ltype === "comment-inline")); + } else { + aa -= 1; + } + //if the last non-comment type is 'item' then id it + if (ltype === "item" && types[aa].indexOf("external") < 0) { + if (type === "start") { + stats.selectors.count += 1; + stats.selectors.chars += itemsize; + if (types[aa - 1] !== "comment" && types[aa - 1] !== "comment-inline" && types[aa - 1] !== "end" && types[aa - 1] !== "start" && types[aa - 1] !== "semi" && types[aa - 1] !== undefined && types[aa - 1].indexOf("external") < 0) { + (function csspretty__tokenize_item_selparts() { + var parts = [], + cc = aa, + dd = 0; + do { + parts.push(token[cc]); + if (spacecol === true && token[cc] === ":" && token[cc - 1] !== ":") { + parts.push(" "); + } + cc -= 1; + } while (cc > -1 && types[cc] !== "comment" && types[cc] !== "comment-inline" && types[cc] !== "end" && types[cc] !== "start" && types[cc] !== "semi" && types[cc] !== undefined); + parts.reverse(); + cc += 1; + dd = aa - cc; + token.splice(cc, dd); + types.splice(cc, dd); + lines.splice(cc, dd); + depth.splice(cc, dd); + begin.splice(cc, dd); + aa -= dd; + token[aa] = parts + .join(" ") + .replace(/(\ *:\ )/g, ":") + .replace(/(\s*,\s*)/g, ","); + }()); + } else { + token[aa] = token[aa].replace(/(\s*,\s*)/g, ","); + } + if (options.compressedcss === true) { + token[aa] = token[aa] + .replace(/\s*&/, " &") + .replace(/(\s*:\s*)/, ":") + .replace(/(\s*>\s*)/g, ">") + .replace(/^(\s+)/, "") + .replace(/(\s+)$/, ""); + } else { + token[aa] = token[aa] + .replace(/\s*&/, " &") + .replace(/(\s*:\s*)/, ":") + .replace(/(\s*>\s*)/g, " > ") + .replace(/^(\s+)/, "") + .replace(/(\s+)$/, ""); + } + (function csspretty__tokenize_item_selectorsort() { + var y = 0, + slen = token[aa].length, + z = "", + mark = 0, + list = []; + for (y = 0; y < slen; y += 1) { + if (z === "" && token[aa].charAt(y) === ",") { + list.push(token[aa].slice(mark, y)); + mark = y + 1; + } else if (token[aa].charAt(y) === "\"" || token[aa].charAt(y) === "'" || token[aa].charAt(y) === "(" || token[aa].charAt(y) === "{") { + z = token[aa].charAt(y); + } else if (token[aa].charAt(y) === z && (z === "\"" || z === "''")) { + z = ""; + } else if (token[aa].charAt(y) === ")" && z === "(") { + z = ""; + } else if (token[aa].charAt(y) === "}" && z === "{") { + z = ""; + } + } + list.push(token[aa].slice(mark, y)); + list.sort(); + token[aa] = list.join(","); + }()); + types[aa] = "selector"; + ltype = "selector"; + } else if (type === "end") { + types[aa] = "value"; + ltype = "value"; if (options.mode !== "diff") { token[aa] = token[aa].replace(/\s*!\s+important/, " !important"); if (options.quoteConvert !== "none" && (token[aa - 2] === "font" || token[aa - 2] === "font-family")) { @@ -846,745 +777,826 @@ global.prettydiff.csspretty = function csspretty_(options) { token[aa] = value(token[aa], false); } } - } else { - //properties without values are considered variables - if (types[aa] !== "value") { - if (types[aa] === "item" && types[aa - 1] === "value" && (toked === "}}" || toked === "?>" || toked === "->" || toked === "%}" || toked === "%>")) { - if (isNaN(token[token.length - 1]) === true) { - token[token.length - 2] = tokel + token.pop(); + //take comments out until the 'item' is found and then put the comments back + if (options.mode === "beautify" || options.mode === "parse" || (options.mode === "diff" && options.diffcomments === true)) { + if (token[token.length - 2] === "{") { + types[types.length - 1] = "propvar"; + stats.values.count -= 1; + stats.values.chars -= itemsize; + stats.variables.count += 1; + stats.variables.chars += itemsize; + } else if (structval === "block") { + if (coms.length > 0 && ltype !== "semi" && ltype !== "end" && ltype !== "start") { + aa = coms.length - 1; + do { + token.pop(); + types.pop(); + lines.pop(); + depth.pop(); + begin.pop(); + aa -= 1; + } while (aa > 0); + if (options.mode === "diff") { + token.push("x;"); + } else { + token.push(";"); + } + depth.push(structval); + begin.push(struct[struct.length - 1]); + types.push("semi"); + lines.push(spacer(false)); + bb = coms.length - 1; + do { + token.push(coms[aa]); + if (coms[aa].indexOf("//") === 0 && lines[lines.length - 1] === 0) { + types.push("comment-inline"); + } else { + types.push("comment"); + } + depth.push(structval); + begin.push(struct[struct.length - 1]); + lines.push(0); + aa += 1; + } while (aa < bb); } else { - token[token.length - 2] = tokel + " " + token.pop(); + if (options.mode === "diff") { + token.push("x;"); + } else { + token.push(";"); + } + depth.push(structval); + begin.push(struct[struct.length - 1]); + types.push("semi"); + lines.push(spacer(false)); } - types.pop(); - return; } - types[aa] = "propvar"; - ltype = "propvar"; } - if (token[aa].indexOf("\"") > 0) { - bb = token[aa].indexOf("\""); - a = a - (token[aa].length - bb); - token[aa] = token[aa].slice(0, bb); - buildtoken(); - } else if (token[aa].indexOf("'") > 0) { - bb = token[aa].indexOf("'"); - a = a - (token[aa].length - bb); - token[aa] = token[aa].slice(0, bb); - buildtoken(); - } else if ((/\s/).test(token[aa]) === true) { - bb = token[aa] - .replace(/\s/, " ") - .indexOf(" "); - if (bb < token[aa].indexOf("(") && bb < token[aa].indexOf("[")) { + stats.values.count += 1; + stats.values.chars += itemsize; + } else if (type === "semi") { + if (types[aa - 1] === "colon") { + stats.values.count += 1; + stats.values.chars += itemsize; + types[aa] = "value"; + ltype = "value"; + if (options.mode !== "diff") { + token[aa] = token[aa].replace(/\s*!\s+important/, " !important"); + if (options.quoteConvert !== "none" && (token[aa - 2] === "font" || token[aa - 2] === "font-family")) { + token[aa] = value(token[aa], true); + } else { + token[aa] = value(token[aa], false); + } + } + } else { + //properties without values are considered variables + if (types[aa] !== "value") { + if (types[aa] === "item" && types[aa - 1] === "value" && (toked === "}}" || toked === "?>" || toked === "->" || toked === "%}" || toked === "%>")) { + if (isNaN(token[token.length - 1]) === true) { + token[token.length - 2] = tokel + token.pop(); + } else { + token[token.length - 2] = tokel + " " + token.pop(); + } + types.pop(); + return; + } + types[aa] = "propvar"; + ltype = "propvar"; + } + if (token[aa].indexOf("\"") > 0) { + bb = token[aa].indexOf("\""); a = a - (token[aa].length - bb); token[aa] = token[aa].slice(0, bb); buildtoken(); + } else if (token[aa].indexOf("'") > 0) { + bb = token[aa].indexOf("'"); + a = a - (token[aa].length - bb); + token[aa] = token[aa].slice(0, bb); + buildtoken(); + } else if ((/\s/).test(token[aa]) === true) { + bb = token[aa] + .replace(/\s/, " ") + .indexOf(" "); + if (bb < token[aa].indexOf("(") && bb < token[aa].indexOf("[")) { + a = a - (token[aa].length - bb); + token[aa] = token[aa].slice(0, bb); + buildtoken(); + } } + stats.variables.count += 1; + stats.variables.chars += itemsize; } - stats.variables.count += 1; - stats.variables.chars += itemsize; + } else if (type === "colon") { + types[aa] = "property"; + ltype = "property"; + stats.properties.count += 1; + stats.properties.chars += itemsize; + } else if (token[aa].charAt(0) === "@" && ((types[aa - 2] !== "propvar" && types[aa - 2] !== "property") || types[aa - 1] === "semi")) { + types[aa] = "propvar"; + ltype = "propvar"; } - } else if (type === "colon") { - types[aa] = "property"; - ltype = "property"; - stats.properties.count += 1; - stats.properties.chars += itemsize; - } else if (token[aa].charAt(0) === "@" && ((types[aa - 2] !== "propvar" && types[aa - 2] !== "property") || types[aa - 1] === "semi")) { - types[aa] = "propvar"; - ltype = "propvar"; } - } - }, - external = function csspretty__tokenize_external(open, end) { - var store = [], - quote = "", - name = "", - endlen = 0, - start = open.length, - linev = spacer(false), - exit = function csspretty__tokenize_external_exit(typename) { - var endtype = types[types.length - 2]; - if (ltype === "item") { - if (endtype === "colon") { - types[types.length - 1] = "value"; - } else { - item(endtype); - } - } - types.push(typename); - }; - nosort[nosort.length - 1] = true; - for (a = a; a < len; a += 1) { - store.push(b[a]); - if (quote === "") { - if (b[a] === "\"") { - quote = "\""; - } else if (b[a] === "'") { - quote = "'"; - } else if (b[a] === "/") { - if (b[a + 1] === "/") { - quote = "/"; - } else if (b[a + 1] === "*") { - quote = "*"; + }, + external = function csspretty__tokenize_external(open, end) { + var store = [], + quote = "", + name = "", + endlen = 0, + start = open.length, + linev = spacer(false), + exit = function csspretty__tokenize_external_exit(typename) { + var endtype = types[types.length - 2]; + if (ltype === "item") { + if (endtype === "colon") { + types[types.length - 1] = "value"; + } else { + item(endtype); + } } - } else if (b[a + 1] === end.charAt(0)) { - do { - endlen += 1; - a += 1; - store.push(b[a]); - } while (a < len && endlen < end.length && b[a + 1] === end.charAt(endlen)); - if (endlen === end.length) { - quote = store.join(""); - if ((/\s/).test(quote.charAt(start)) === true) { - do { - start += 1; - } while ((/\s/).test(quote.charAt(start)) === true); + types.push(typename); + }; + nosort[nosort.length - 1] = true; + for (a = a; a < len; a += 1) { + store.push(b[a]); + if (quote === "") { + if (b[a] === "\"") { + quote = "\""; + } else if (b[a] === "'") { + quote = "'"; + } else if (b[a] === "/") { + if (b[a + 1] === "/") { + quote = "/"; + } else if (b[a + 1] === "*") { + quote = "*"; } - endlen = start; + } else if (b[a + 1] === end.charAt(0)) { do { endlen += 1; - } while (endlen < end.length && (/\s/).test(quote.charAt(endlen)) === false); - if (endlen === quote.length) { - endlen -= end.length; - } - if (open === "{%") { - if (quote.indexOf("{%-") === 0) { - quote = quote - .replace(/^(\{%-\s*)/, "{%- ") - .replace(/(\s*-%\})$/, " -%}"); - name = quote.slice(4); - } else { - quote = quote - .replace(/^(\{%\s*)/, "{% ") - .replace(/(\s*%\})$/, " %}"); - name = quote.slice(3); + a += 1; + store.push(b[a]); + } while (a < len && endlen < end.length && b[a + 1] === end.charAt(endlen)); + if (endlen === end.length) { + quote = store.join(""); + if ((/\s/).test(quote.charAt(start)) === true) { + do { + start += 1; + } while ((/\s/).test(quote.charAt(start)) === true); } - } - if (open === "{{") { - quote = quote - .replace(/^(\{\{\s+)/, "{{") - .replace(/(\s+\}\})$/, "}}"); - } - if (ltype === "item" && types[types.length - 2] === "colon" && (types[types.length - 3] === "property" || types[types.length - 3] === "propvar")) { - ltype = "value"; - types[types.length - 1] = "value"; - if (isNaN(token[token.length - 1]) === true && token[token.length - 1].charAt(token[token.length - 1].length - 1) !== ")") { - token[token.length - 1] = token[token.length - 1] + quote; - } else { - token[token.length - 1] = token[token.length - 1] + " " + quote; + endlen = start; + do { + endlen += 1; + } while (endlen < end.length && (/\s/).test(quote.charAt(endlen)) === false); + if (endlen === quote.length) { + endlen -= end.length; } - return; - } - lines.push(linev); - token.push(quote); - begin.push(struct[struct.length - 1]); - depth.push(structval); - if (open === "{%") { - name = name.slice(0, name.indexOf(" ")); - if (name.indexOf("(") > 0) { - name = name.slice(0, name.indexOf("(")); + if (open === "{%") { + if (quote.indexOf("{%-") === 0) { + quote = quote + .replace(/^(\{%-\s*)/, "{%- ") + .replace(/(\s*-%\})$/, " -%}"); + name = quote.slice(4); + } else { + quote = quote + .replace(/^(\{%\s*)/, "{% ") + .replace(/(\s*%\})$/, " %}"); + name = quote.slice(3); + } } - store = [ - "autoescape", - "block", - "capture", - "case", - "comment", - "embed", - "filter", - "for", - "form", - "if", - "macro", - "paginate", - "raw", - "sandbox", - "spaceless", - "tablerow", - "unless", - "verbatim" - ]; - if (name === "else" || name === "elseif" || name === "when" || name === "elif") { - return exit("external_else"); + if (open === "{{") { + quote = quote + .replace(/^(\{\{\s+)/, "{{") + .replace(/(\s+\}\})$/, "}}"); } - for (endlen = store.length - 1; endlen > -1; endlen -= 1) { - if (name === store[endlen]) { - return exit("external_start"); + if (ltype === "item" && types[types.length - 2] === "colon" && (types[types.length - 3] === "property" || types[types.length - 3] === "propvar")) { + ltype = "value"; + types[types.length - 1] = "value"; + if (isNaN(token[token.length - 1]) === true && token[token.length - 1].charAt(token[token.length - 1].length - 1) !== ")") { + token[token.length - 1] = token[token.length - 1] + quote; + } else { + token[token.length - 1] = token[token.length - 1] + " " + quote; + } + return; + } + lines.push(linev); + token.push(quote); + begin.push(struct[struct.length - 1]); + depth.push(structval); + if (open === "{%") { + name = name.slice(0, name.indexOf(" ")); + if (name.indexOf("(") > 0) { + name = name.slice(0, name.indexOf("(")); + } + store = [ + "autoescape", + "block", + "capture", + "case", + "comment", + "embed", + "filter", + "for", + "form", + "if", + "macro", + "paginate", + "raw", + "sandbox", + "spaceless", + "tablerow", + "unless", + "verbatim" + ]; + if (name === "else" || name === "elseif" || name === "when" || name === "elif") { + return exit("external_else"); + } + for (endlen = store.length - 1; endlen > -1; endlen -= 1) { + if (name === store[endlen]) { + return exit("external_start"); + } + if (name === "end" + store[endlen]) { + return exit("external_end"); + } + } + } else if (open === "{{") { + name = quote.slice(2); + endlen = name.length; + start = 0; + do { + start += 1; + } while (start < endlen && (/\s/).test(name.charAt(start)) === false && name.charAt(start) !== "("); + name = name.slice(0, start); + if (name.charAt(name.length - 2) === "}") { + name = name.slice(0, name.length - 2); } - if (name === "end" + store[endlen]) { + if (name === "end") { return exit("external_end"); } + if (name === "block" || name === "define" || name === "form" || name === "if" || name === "range" || name === "with") { + return exit("external_start"); + } } - } else if (open === "{{") { - name = quote.slice(2); - endlen = name.length; - start = 0; - do { - start += 1; - } while (start < endlen && (/\s/).test(name.charAt(start)) === false && name.charAt(start) !== "("); - name = name.slice(0, start); - if (name.charAt(name.length - 2) === "}") { - name = name.slice(0, name.length - 2); - } - if (name === "end") { - return exit("external_end"); - } - if (name === "block" || name === "define" || name === "form" || name === "if" || name === "range" || name === "with") { - return exit("external_start"); - } + return exit("external"); } - return exit("external"); + endlen = 0; + } + } else if (quote === b[a]) { + if (quote === "\"" || quote === "'") { + quote = ""; + } else if (quote === "/" && (b[a] === "\r" || b[a] === "\n")) { + quote = ""; + } else if (quote === "*" && b[a + 1] === "/") { + quote = ""; } - endlen = 0; - } - } else if (quote === b[a]) { - if (quote === "\"" || quote === "'") { - quote = ""; - } else if (quote === "/" && (b[a] === "\r" || b[a] === "\n")) { - quote = ""; - } else if (quote === "*" && b[a + 1] === "/") { - quote = ""; } } - } - }, - //finds comments include those JS looking '//' comments - comment = function csspretty__tokenize_comment(inline) { - var aa = 0, - bb = 0, - out = [b[a]], - type = "comment", - extra = "", - spareType = [], - spareToke = [], - spareLine = [], - spareBegn = [], - spareDept = [], - linev = spacer(false); - type = (inline === true && linev === 0) - ? "comment-inline" - : "comment"; - for (aa = a + 1; aa < len; aa += 1) { - out.push(b[aa]); - if ((inline === false && b[aa - 1] === "*" && b[aa] === "/") || (inline === true && (b[aa + 1] === "\n" || b[aa + 1] === "\r"))) { - break; + }, + //finds comments include those JS looking '//' comments + comment = function csspretty__tokenize_comment(inline) { + var aa = 0, + bb = 0, + out = [b[a]], + type = "comment", + extra = "", + spareType = [], + spareToke = [], + spareLine = [], + spareBegn = [], + spareDept = [], + linev = spacer(false); + type = (inline === true && linev === 0) + ? "comment-inline" + : "comment"; + for (aa = a + 1; aa < len; aa += 1) { + out.push(b[aa]); + if ((inline === false && b[aa - 1] === "*" && b[aa] === "/") || (inline === true && (b[aa + 1] === "\n" || b[aa + 1] === "\r"))) { + break; + } } - } - if (ltype === "item") { - bb = aa; - do { - bb += 1; - if (b[bb] === "/") { - if (b[bb + 1] === "*" || b[bb + 1] === "/") { - extra = b[bb + 1]; - } else if (b[bb - 1] === "*" && extra === "*") { + if (ltype === "item") { + bb = aa; + do { + bb += 1; + if (b[bb] === "/") { + if (b[bb + 1] === "*" || b[bb + 1] === "/") { + extra = b[bb + 1]; + } else if (b[bb - 1] === "*" && extra === "*") { + extra = ""; + bb += 1; + } + } else if ((b[bb] === "\n" || b[bb] === "\r") && extra === "/") { extra = ""; bb += 1; } - } else if ((b[bb] === "\n" || b[bb] === "\r") && extra === "/") { - extra = ""; - bb += 1; - } - } while (bb < len && ((extra === "" && (/\s/).test(b[bb]) === true) || extra !== "")); - if (b[bb] === "{") { - item("start"); - } else if (b[bb] === "}") { - item("end"); - } else if (b[bb] === ";") { - item("semi"); - } else if (b[bb] === ":") { - item("colon"); - } else { - item(); - } - } - a = aa; - stats.comments.count += 1; - stats.comments.chars += out.length; - if (options.mode === "minify") { - out.push(lf); - } - if (options.mode === "beautify" || options.mode === "parse" || (options.mode === "diff" && options.diffcomments === true) || (options.mode === "minify" && options.topcoms === true)) { - if (token.length > 0 && (ltype === "selector" || ltype === "propvar") && types[types.length - 1] !== "comment" && types[types.length - 1] !== "comment-inline") { - spareToke.push(token[token.length - 1]); - token.pop(); - types.pop(); - lines.pop(); - begin.pop(); - depth.pop(); - begin.push(struct[struct.length - 1]); - depth.push(structval); - token.push(out.join("")); - types.push(type); - lines.push(linev); - begin.push(struct[struct.length - 1]); - depth.push(structval); - token.push(spareToke[0]); - if (ltype === "propvar") { - types.push("propvar"); + } while (bb < len && ((extra === "" && (/\s/).test(b[bb]) === true) || extra !== "")); + if (b[bb] === "{") { + item("start"); + } else if (b[bb] === "}") { + item("end"); + } else if (b[bb] === ";") { + item("semi"); + } else if (b[bb] === ":") { + item("colon"); } else { - types.push("selector"); + item(); } - lines.push(0); - } else if (ltype === "colon" || ltype === "property" || ltype === "value" || ltype === "propvar") { - do { + } + a = aa; + stats.comments.count += 1; + stats.comments.chars += out.length; + if (options.mode === "minify") { + out.push(lf); + } + if (options.mode === "beautify" || options.mode === "parse" || (options.mode === "diff" && options.diffcomments === true) || (options.mode === "minify" && options.topcoms === true)) { + if (token.length > 0 && (ltype === "selector" || ltype === "propvar") && types[types.length - 1] !== "comment" && types[types.length - 1] !== "comment-inline") { spareToke.push(token[token.length - 1]); - spareType.push(types[types.length - 1]); - spareLine.push(lines[lines.length - 1]); - spareDept.push(depth[depth.length - 1]); - spareBegn.push(begin[begin.length - 1]); token.pop(); types.pop(); lines.pop(); - depth.pop(); begin.pop(); - } while (types.length > 1 && types[types.length - 1] !== "semi" && types[types.length - 1] !== "start"); - token.push(out.join("")); - types.push(type); - lines.push(linev); - depth.push(structval); - begin.push(struct[struct.length - 1]); - do { - token.push(spareToke[spareToke.length - 1]); - types.push(spareType[spareType.length - 1]); - lines.push(spareLine[spareLine.length - 1]); - depth.push(spareDept[spareDept.length - 1]); - begin.push(spareBegn[spareBegn.length - 1]); - spareToke.pop(); - spareType.pop(); - spareLine.pop(); - spareDept.pop(); - spareBegn.pop(); - } while (spareToke.length > 0); - } else { - ltype = type; - types.push(type); - token.push(out.join("")); - lines.push(linev); - depth.push(structval); - begin.push(struct[struct.length - 1]); - } - } - }, - //do fancy things to property types like: sorting, consolidating, and padding - properties = function csspretty__tokenize_properties() { - var aa = 0, - bb = 1, - cc = 0, - dd = 0, - p = [], - set = [ - [] - ], - next = 0, - stoke = [], - stype = [], - sline = [], - sdept = [], - sbegn = []; - //identify properties and build out prop/val sets - for (aa = token.length - 1; aa > -1; aa -= 1) { - if (types[aa] === "start") { - bb -= 1; - if (bb === 0) { - next = aa; - set.pop(); - for (aa = set.length - 1; aa > -1; aa -= 1) { - set[aa].reverse(); + depth.pop(); + begin.push(struct[struct.length - 1]); + depth.push(structval); + token.push(out.join("")); + types.push(type); + lines.push(linev); + begin.push(struct[struct.length - 1]); + depth.push(structval); + token.push(spareToke[0]); + if (ltype === "propvar") { + types.push("propvar"); + } else { + types.push("selector"); } - break; + lines.push(0); + } else if (ltype === "colon" || ltype === "property" || ltype === "value" || ltype === "propvar") { + do { + spareToke.push(token[token.length - 1]); + spareType.push(types[types.length - 1]); + spareLine.push(lines[lines.length - 1]); + spareDept.push(depth[depth.length - 1]); + spareBegn.push(begin[begin.length - 1]); + token.pop(); + types.pop(); + lines.pop(); + depth.pop(); + begin.pop(); + } while (types.length > 1 && types[types.length - 1] !== "semi" && types[types.length - 1] !== "start"); + token.push(out.join("")); + types.push(type); + lines.push(linev); + depth.push(structval); + begin.push(struct[struct.length - 1]); + do { + token.push(spareToke[spareToke.length - 1]); + types.push(spareType[spareType.length - 1]); + lines.push(spareLine[spareLine.length - 1]); + depth.push(spareDept[spareDept.length - 1]); + begin.push(spareBegn[spareBegn.length - 1]); + spareToke.pop(); + spareType.pop(); + spareLine.pop(); + spareDept.pop(); + spareBegn.pop(); + } while (spareToke.length > 0); + } else { + ltype = type; + types.push(type); + token.push(out.join("")); + lines.push(linev); + depth.push(structval); + begin.push(struct[struct.length - 1]); } } - if (types[aa] === "end") { - bb += 1; - } - if (bb === 1 && (types[aa] === "property" || (types[aa] === "propvar" && types[aa + 1] === "colon")) && options.mode === "beautify") { - p.push(aa); - } - set[set.length - 1].push(aa); - if (bb === 1 && (types[aa - 1] === "comment" || types[aa - 1] === "comment-inline" || types[aa - 1] === "semi" || types[aa - 1] === "end" || types[aa - 1] === "start") && types[aa] !== "start" && types[aa] !== "end") { - set.push([]); + }, + //do fancy things to property types like: sorting, consolidating, and padding + properties = function csspretty__tokenize_properties() { + var aa = 0, + bb = 1, + cc = 0, + dd = 0, + p = [], + set = [ + [] + ], + next = 0, + stoke = [], + stype = [], + sline = [], + sdept = [], + sbegn = []; + //identify properties and build out prop/val sets + for (aa = token.length - 1; aa > -1; aa -= 1) { + if (types[aa] === "start") { + bb -= 1; + if (bb === 0) { + next = aa; + set.pop(); + for (aa = set.length - 1; aa > -1; aa -= 1) { + set[aa].reverse(); + } + break; + } + } + if (types[aa] === "end") { + bb += 1; + } + if (bb === 1 && (types[aa] === "property" || (types[aa] === "propvar" && types[aa + 1] === "colon")) && options.mode === "beautify") { + p.push(aa); + } + set[set.length - 1].push(aa); + if (bb === 1 && (types[aa - 1] === "comment" || types[aa - 1] === "comment-inline" || types[aa - 1] === "semi" || types[aa - 1] === "end" || types[aa - 1] === "start") && types[aa] !== "start" && types[aa] !== "end") { + set.push([]); + } } - } - //this reverse fixes the order of consecutive comments - set.reverse(); - p.reverse(); + //this reverse fixes the order of consecutive comments + set.reverse(); + p.reverse(); - //consolidate margin and padding - (function csspretty__tokenize_properties_propcheck() { - var leng = set.length, - fourcount = function csspretty__tokenize_properties_propcheck_fourcount(name) { - var test = [ - false, false, false, false - ], - value = [ - "0", "0", "0", "0" - ], - zero = (/^(0+([a-z]+|%))/), - start = aa, - yy = -1, - zz = 0, - valsplit = [], - store = function csspretty__tokenize_properties_propcheck_fourcount_store(side) { - yy += 1; - value[side] = token[set[aa][2]]; - test[side] = true; - if (start < 0) { - start = aa; - } - }; - for (aa = aa; aa < leng; aa += 1) { - if (token[set[aa][2]] !== undefined && token[set[aa][0]].indexOf(name) === 0) { - if (token[set[aa][0]] === name || token[set[aa][0]].indexOf(name + " ") === 0) { - yy += 1; - valsplit = token[set[aa][2]].split(" "); - if (valsplit.length === 1) { - value = [ - token[set[aa][2]], - token[set[aa][2]], - token[set[aa][2]], - token[set[aa][2]] - ]; - } else if (valsplit.length === 2) { - value = [valsplit[0], valsplit[1], valsplit[0], valsplit[1]]; - } else if (valsplit.length === 3) { - value = [valsplit[0], valsplit[1], valsplit[2], valsplit[1]]; - } else if (valsplit.length === 4) { - value = [valsplit[0], valsplit[1], valsplit[2], valsplit[3]]; - } else { - return; + //consolidate margin and padding + (function csspretty__tokenize_properties_propcheck() { + var leng = set.length, + fourcount = function csspretty__tokenize_properties_propcheck_fourcount(name) { + var test = [ + false, false, false, false + ], + value = [ + "0", "0", "0", "0" + ], + zero = (/^(0+([a-z]+|%))/), + start = aa, + yy = -1, + zz = 0, + valsplit = [], + store = function csspretty__tokenize_properties_propcheck_fourcount_store(side) { + yy += 1; + value[side] = token[set[aa][2]]; + test[side] = true; + if (start < 0) { + start = aa; } - test = [true, true, true, true]; - } else if (token[set[aa][0]].indexOf(name + "-bottom") === 0) { - store(2); - } else if (token[set[aa][0]].indexOf(name + "-left") === 0) { - store(3); - } else if (token[set[aa][0]].indexOf(name + "-right") === 0) { - store(1); - } else if (token[set[aa][0]].indexOf(name + "-top") === 0) { - store(0); - } - } - if (set[aa + 1] === undefined || token[set[aa + 1][0]].indexOf(name) < 0 || aa === leng - 1) { - if (test[0] === true && test[1] === true && test[2] === true && test[3] === true) { - set.splice(start + 1, yy); - leng -= yy; - aa -= yy; - zz = 0; - bb = p.length; - do { - if (p[zz] === set[start][0]) { - break; + }; + for (aa = aa; aa < leng; aa += 1) { + if (token[set[aa][2]] !== undefined && token[set[aa][0]].indexOf(name) === 0) { + if (token[set[aa][0]] === name || token[set[aa][0]].indexOf(name + " ") === 0) { + yy += 1; + valsplit = token[set[aa][2]].split(" "); + if (valsplit.length === 1) { + value = [ + token[set[aa][2]], + token[set[aa][2]], + token[set[aa][2]], + token[set[aa][2]] + ]; + } else if (valsplit.length === 2) { + value = [valsplit[0], valsplit[1], valsplit[0], valsplit[1]]; + } else if (valsplit.length === 3) { + value = [valsplit[0], valsplit[1], valsplit[2], valsplit[1]]; + } else if (valsplit.length === 4) { + value = [valsplit[0], valsplit[1], valsplit[2], valsplit[3]]; + } else { + return; } - zz += 1; - } while (zz < bb); - if (zz < bb) { - p.splice(zz + 1, yy); - } - token[set[start][0]] = name; - if (zero.test(value[0]) === true) { - value[0] = "0"; + test = [true, true, true, true]; + } else if (token[set[aa][0]].indexOf(name + "-bottom") === 0) { + store(2); + } else if (token[set[aa][0]].indexOf(name + "-left") === 0) { + store(3); + } else if (token[set[aa][0]].indexOf(name + "-right") === 0) { + store(1); + } else if (token[set[aa][0]].indexOf(name + "-top") === 0) { + store(0); } - if (zero.test(value[1]) === true) { - value[1] = "0"; - } - if (zero.test(value[2]) === true) { - value[2] = "0"; - } - if (zero.test(value[3]) === true) { - value[3] = "0"; - } - if (value[1] === value[3]) { - value.pop(); - if (value[0] === value[2]) { + } + if (set[aa + 1] === undefined || token[set[aa + 1][0]].indexOf(name) < 0 || aa === leng - 1) { + if (test[0] === true && test[1] === true && test[2] === true && test[3] === true) { + set.splice(start + 1, yy); + leng -= yy; + aa -= yy; + zz = 0; + bb = p.length; + do { + if (p[zz] === set[start][0]) { + break; + } + zz += 1; + } while (zz < bb); + if (zz < bb) { + p.splice(zz + 1, yy); + } + token[set[start][0]] = name; + if (zero.test(value[0]) === true) { + value[0] = "0"; + } + if (zero.test(value[1]) === true) { + value[1] = "0"; + } + if (zero.test(value[2]) === true) { + value[2] = "0"; + } + if (zero.test(value[3]) === true) { + value[3] = "0"; + } + if (value[1] === value[3]) { value.pop(); - if (value[0] === value[1]) { + if (value[0] === value[2]) { value.pop(); + if (value[0] === value[1]) { + value.pop(); + } } } - } - token[set[start][2]] = value.join(" "); - if (token[set[start][2]].indexOf("!important") > 0) { - token[set[start][2]] = token[set[start][2]].replace(/\s!important/g, "") + " !important"; - } - if (options.mode === "beautify" && verticalop === true) { - if (token[set[start][0]].charAt(token[set[start][0]].length - 1) === " ") { - yy = token[set[start][0]].length - name.length; - do { - name = name + " "; - yy -= 1; - } while (yy > 0); + token[set[start][2]] = value.join(" "); + if (token[set[start][2]].indexOf("!important") > 0) { + token[set[start][2]] = token[set[start][2]].replace(/\s!important/g, "") + " !important"; + } + if (options.mode === "beautify" && verticalop === true) { + if (token[set[start][0]].charAt(token[set[start][0]].length - 1) === " ") { + yy = token[set[start][0]].length - name.length; + do { + name = name + " "; + yy -= 1; + } while (yy > 0); + } } } + break; } - break; + } + }; + for (aa = 0; aa < leng; aa += 1) { + if (types[set[aa][0]] === "property") { + if (token[set[aa][0]].indexOf("margin") === 0) { + fourcount("margin"); + } + if (token[set[aa][0]].indexOf("padding") === 0) { + fourcount("padding"); } } - }; - for (aa = 0; aa < leng; aa += 1) { - if (types[set[aa][0]] === "property") { - if (token[set[aa][0]].indexOf("margin") === 0) { - fourcount("margin"); + } + }()); + + //pad out those property names so that the colons are vertically aligned + if (verticalop === true) { + bb = 0; + for (aa = p.length - 1; aa > -1; aa -= 1) { + if (token[p[aa]].length > bb && token[p[aa]] !== "filter" && token[p[aa]] !== "progid") { + bb = token[p[aa]].length; } - if (token[set[aa][0]].indexOf("padding") === 0) { - fourcount("padding"); + } + for (aa = p.length - 1; aa > -1; aa -= 1) { + cc = bb - token[p[aa]].length; + if (cc > 0 && token[p[aa]] !== "filter" && token[p[aa]] !== "progid") { + do { + token[p[aa]] = token[p[aa]] + " "; + cc -= 1; + } while (cc > 0); } } + if (endtest === false) { + return; + } } - }()); - //pad out those property names so that the colons are vertically aligned - if (verticalop === true) { - bb = 0; - for (aa = p.length - 1; aa > -1; aa -= 1) { - if (token[p[aa]].length > bb && token[p[aa]] !== "filter" && token[p[aa]] !== "progid") { - bb = token[p[aa]].length; + bb = set.length; + for (aa = 0; aa < bb; aa += 1) { + dd = set[aa].length; + for (cc = 0; cc < dd; cc += 1) { + stoke.push(token[set[aa][cc]]); + stype.push(types[set[aa][cc]]); + sline.push(lines[set[aa][cc]]); + sdept.push(depth[set[aa][cc]]); + sbegn.push(begin[set[aa][cc]]); } } - for (aa = p.length - 1; aa > -1; aa -= 1) { - cc = bb - token[p[aa]].length; - if (cc > 0 && token[p[aa]] !== "filter" && token[p[aa]] !== "progid") { - do { - token[p[aa]] = token[p[aa]] + " "; - cc -= 1; - } while (cc > 0); - } + //replace a block's data with sorted analyzed data + token.splice(next + 1, token.length - next - 1); + types.splice(next + 1, types.length - next - 1); + lines.splice(next + 1, lines.length - next - 1); + depth.splice(next + 1, depth.length - next - 1); + begin.splice(next + 1, begin.length - next - 1); + token = token.concat(stoke); + types = types.concat(stype); + lines = lines.concat(sline); + depth = depth.concat(sdept); + begin = begin.concat(sbegn); + }; + //token building loop + for (a = 0; a < len; a += 1) { + if (ltype !== "comment" && ltype !== "comment-inline" && ltype !== "" && options.topcoms === true) { + options.topcoms = false; + } + if ((/\s/).test(b[a]) === true) { + stats.space += 1; + space += b[a]; + } else if (b[a] === "/" && b[a + 1] === "*") { + comment(false); + } else if (b[a] === "/" && b[a + 1] === "/") { + comment(true); + } else if (b[a] === "<" && b[a + 1] === "?" && b[a + 2] === "p" && b[a + 3] === "h" && b[a + 4] === "p") { + //php + external(""); + } else if (b[a] === "<" && b[a + 1] === "%") { + //asp + external("<%", "%>"); + } else if (b[a] === "{" && b[a + 1] === "%") { + //asp + external("{%", "%}"); + } else if (b[a] === "{" && b[a + 1] === "{" && b[a + 2] === "{") { + //mustache + external("{{{", "}}}"); + } else if (b[a] === "{" && b[a + 1] === "{") { + //handlebars + external("{{", "}}"); + } else if (b[a] === "<" && b[a + 1] === "!" && b[a + 2] === "-" && b[a + 3] === "-" && b[a + 4] === "#") { + //ssi + external(""); + } else if (b[a] === "{" || (b[a] === "(" && token[token.length - 1] === ":" && types[types.length - 2] === "propvar")) { + if (b[a] === "{" && token[token.length - 2] === ":") { + types[types.length - 1] = "pseudo"; } - if (endtest === false) { - return; + item("start"); + struct.push(token.length); + ltype = "start"; + types.push("start"); + token.push(b[a]); + begin.push(token.length); + if (b[a] === "(") { + structval = "map"; + depth.push("map"); + mapper.push(0); + } else { + structval = "block"; + depth.push("block"); } - } - - bb = set.length; - for (aa = 0; aa < bb; aa += 1) { - dd = set[aa].length; - for (cc = 0; cc < dd; cc += 1) { - stoke.push(token[set[aa][cc]]); - stype.push(types[set[aa][cc]]); - sline.push(lines[set[aa][cc]]); - sdept.push(depth[set[aa][cc]]); - sbegn.push(begin[set[aa][cc]]); + nosort.push(false); + lines.push(spacer(false)); + stats.braces += 1; + spacecol = false; + } else if (b[a] === "}" || (b[a] === ")" && structval === "map" && mapper[mapper.length - 1] === 0)) { + endtest = true; + if (b[a] === "}" && types[types.length - 1] === "item" && token[token.length - 2] === "{" && token[token.length - 3] !== undefined && token[token.length - 3].charAt(token[token.length - 3].length - 1) === "@") { + token[token.length - 3] = token[token.length - 3] + "{" + token[token.length - 1] + "}"; + token.pop(); + token.pop(); + types.pop(); + types.pop(); + lines.pop(); + lines.pop(); + depth.pop(); + depth.pop(); + begin.pop(); + begin.pop(); + } else { + if (b[a] === ")") { + mapper.pop(); + } else if (b[a] === "}" && ltype === "value" && token[token.length - 1] !== ";") { + token.push(";"); + types.push("semi"); + lines.push(0); + depth.push("block"); + begin.push(begin[begin.length - 1]); + } + item("end"); + if (options.mode !== "diff") { + properties(); + } + ltype = "end"; + if (objsortop === true && nosort[nosort.length - 1] === false) { + objSort(); + } + nosort.pop(); + types.push("end"); + token.push(b[a]); + lines.push(spacer(false)); + depth.push(structval); + begin.push(struct[struct.length - 1]); + stats.braces += 1; } - } - //replace a block's data with sorted analyzed data - token.splice(next + 1, token.length - next - 1); - types.splice(next + 1, types.length - next - 1); - lines.splice(next + 1, lines.length - next - 1); - depth.splice(next + 1, depth.length - next - 1); - begin.splice(next + 1, begin.length - next - 1); - token = token.concat(stoke); - types = types.concat(stype); - lines = lines.concat(sline); - depth = depth.concat(sdept); - begin = begin.concat(sbegn); - }; - //token building loop - for (a = 0; a < len; a += 1) { - if (ltype !== "comment" && ltype !== "comment-inline" && ltype !== "" && options.topcoms === true) { - options.topcoms = false; - } - if ((/\s/).test(b[a]) === true) { - stats.space += 1; - space += b[a]; - } else if (b[a] === "/" && b[a + 1] === "*") { - comment(false); - } else if (b[a] === "/" && b[a + 1] === "/") { - comment(true); - } else if (b[a] === "<" && b[a + 1] === "?" && b[a + 2] === "p" && b[a + 3] === "h" && b[a + 4] === "p") { - //php - external(""); - } else if (b[a] === "<" && b[a + 1] === "%") { - //asp - external("<%", "%>"); - } else if (b[a] === "{" && b[a + 1] === "%") { - //asp - external("{%", "%}"); - } else if (b[a] === "{" && b[a + 1] === "{" && b[a + 2] === "{") { - //mustache - external("{{{", "}}}"); - } else if (b[a] === "{" && b[a + 1] === "{") { - //handlebars - external("{{", "}}"); - } else if (b[a] === "<" && b[a + 1] === "!" && b[a + 2] === "-" && b[a + 3] === "-" && b[a + 4] === "#") { - //ssi - external(""); - } else if (b[a] === "{" || (b[a] === "(" && token[token.length - 1] === ":" && types[types.length - 2] === "propvar")) { - if (b[a] === "{" && token[token.length - 2] === ":") { - types[types.length - 1] = "pseudo"; - } - item("start"); - struct.push(token.length); - ltype = "start"; - types.push("start"); - token.push(b[a]); - begin.push(token.length); - if (b[a] === "(") { - structval = "map"; - depth.push("map"); - mapper.push(0); - } else { - structval = "block"; - depth.push("block"); - } - nosort.push(false); - lines.push(spacer(false)); - stats.braces += 1; - spacecol = false; - } else if (b[a] === "}" || (b[a] === ")" && structval === "map" && mapper[mapper.length - 1] === 0)) { - endtest = true; - if (b[a] === "}" && types[types.length - 1] === "item" && token[token.length - 2] === "{" && token[token.length - 3] !== undefined && token[token.length - 3].charAt(token[token.length - 3].length - 1) === "@") { - token[token.length - 3] = token[token.length - 3] + "{" + token[token.length - 1] + "}"; - token.pop(); - token.pop(); - types.pop(); - types.pop(); - lines.pop(); - lines.pop(); - depth.pop(); - depth.pop(); - begin.pop(); - begin.pop(); - } else { - if (b[a] === ")") { - mapper.pop(); - } else if (b[a] === "}" && ltype === "value" && token[token.length - 1] !== ";") { - token.push(";"); + struct.pop(); + if (token[struct[struct.length - 1]] === "{") { + structval = "block"; + } else if (token[struct[struct.length - 1]] === "(") { + structval = "map"; + } else { + structval = "root"; + } + } else if (b[a] === ";" || (b[a] === "," && structval === "map")) { + item("semi"); + if (types[types.length - 1] !== "semi" && types[types.length - 1] !== "start" && esctest(a) === false) { + ltype = "semi"; types.push("semi"); - lines.push(0); - depth.push("block"); + token.push(b[a]); + lines.push(spacer(false)); + depth.push(structval); begin.push(begin[begin.length - 1]); } - item("end"); - if (options.mode !== "diff") { - properties(); - } - ltype = "end"; - if (objsortop === true && nosort[nosort.length - 1] === false) { - objSort(); + stats.semi += 1; + space = ""; + } else if (b[a] === ":" && types[types.length - 1] !== "end") { + item("colon"); + types.push("colon"); + token.push(":"); + lines.push(0); + ltype = "colon"; + stats.colon += 1; + space = ""; + if ((/\s/).test(b[a - 1]) === true) { + spacecol = true; + } else if (b[a - 1] !== ":") { + spacecol = false; } - nosort.pop(); - types.push("end"); - token.push(b[a]); - lines.push(spacer(false)); - depth.push(structval); - begin.push(struct[struct.length - 1]); - stats.braces += 1; - } - struct.pop(); - if (token[struct[struct.length - 1]] === "{") { - structval = "block"; - } else if (token[struct[struct.length - 1]] === "(") { - structval = "map"; } else { - structval = "root"; - } - } else if (b[a] === ";" || (b[a] === "," && structval === "map")) { - item("semi"); - if (types[types.length - 1] !== "semi" && types[types.length - 1] !== "start" && esctest(a) === false) { - ltype = "semi"; - types.push("semi"); - token.push(b[a]); - lines.push(spacer(false)); - depth.push(structval); - begin.push(begin[begin.length - 1]); - } - stats.semi += 1; - space = ""; - } else if (b[a] === ":" && types[types.length - 1] !== "end") { - item("colon"); - types.push("colon"); - token.push(":"); - lines.push(0); - ltype = "colon"; - stats.colon += 1; - space = ""; - if ((/\s/).test(b[a - 1]) === true) { - spacecol = true; - } else if (b[a - 1] !== ":") { - spacecol = false; - } - } else { - if (structval === "map" && b[a] === "(") { - mapper[mapper.length - 1] += 1; + if (structval === "map" && b[a] === "(") { + mapper[mapper.length - 1] += 1; + } + buildtoken(); } - buildtoken(); } - } - if (endtest === false && verticalop === true) { - properties(); - } - }()); - - if (options.mode === "parse") { - return (function csspretty__parse() { - var a = 0, - c = token.length, - record = [], - def = { - token: "string - The parsed code tokens", - types: "string - Data types of the tokens: colon, comment, comment-inline, end, external, external_else, external_end, external_start, item, propvar, pseudo, selector, semi, start, value", - lines: "number - Whether the token is preceeded any space and/or line breaks in the original code source", - depth: "string - Type of current structure", - begin: "number - Index where current structure begins" - }; - if (options.parseFormat === "sequential") { - for (a = 0; a < c; a += 1) { - record.push([token[a], types[a], lines[a], depth[a], begin[a]]); - } - if (options.nodeasync === true) { - return [{ - data : record, - definition: def - }, ""]; - } - return { - data : record, - definition: def - }; + if (endtest === false && verticalop === true) { + properties(); } - if (options.parseFormat === "htmltable") { - return (function csspretty__parse_html() { - var report = [], - aa = 0, - len = 0; - report.push(""); - report.push(""); - report.push(""); - report.push(""); - report.push(""); - report.push(""); - report.push(""); - len = token.length; - for (aa = 0; aa < len; aa += 1) { - report.push(""); + }()); + + if (options.mode === "parse") { + return (function csspretty__parse() { + var a = 0, + c = token.length, + record = [], + def = { + token: "string - The parsed code tokens", + types: "string - Data types of the tokens: colon, comment, comment-inline, end, external, external_else, external_end, external_start, item, propvar, pseudo, selector, semi, start, value", + lines: "number - Whether the token is preceeded any space and/or line breaks in the original code source", + depth: "string - Type of current structure", + begin: "number - Index where current structure begins" + }; + if (options.parseFormat === "sequential") { + for (a = 0; a < c; a += 1) { + record.push([token[a], types[a], lines[a], depth[a], begin[a]]); } - report.push("
indextokentypeslinesdepthbegin
"); - report.push(aa); - report.push(""); - report.push(token[aa].replace(/&/g, "&").replace(/>/g, ">").replace(/"); - report.push(types[aa]); - report.push(""); - report.push(lines[aa]); - report.push(""); - report.push(depth[aa]); - report.push(""); - report.push(begin[aa]); - report.push("
"); if (options.nodeasync === true) { return [{ - data : report.join(""), + data : record, definition: def }, ""]; } return { - data : report.join(""), + data : record, definition: def }; - }()); - } - if (options.nodeasync === true) { - return [{ + } + if (options.parseFormat === "htmltable") { + return (function csspretty__parse_html() { + var report = [], + aa = 0, + len = 0; + report.push(""); + report.push(""); + report.push(""); + report.push(""); + report.push(""); + report.push(""); + report.push(""); + len = token.length; + for (aa = 0; aa < len; aa += 1) { + report.push(""); + } + report.push("
indextokentypeslinesdepthbegin
"); + report.push(aa); + report.push(""); + report.push(token[aa].replace(/&/g, "&").replace(/>/g, ">").replace(/"); + report.push(types[aa]); + report.push(""); + report.push(lines[aa]); + report.push(""); + report.push(depth[aa]); + report.push(""); + report.push(begin[aa]); + report.push("
"); + if (options.nodeasync === true) { + return [{ + data : report.join(""), + definition: def + }, ""]; + } + return { + data : report.join(""), + definition: def + }; + }()); + } + if (options.nodeasync === true) { + return [{ + data : { + token: token, + types: types, + lines: lines, + depth: depth, + begin: begin + }, + definition: def + }, ""]; + } + return { data : { token: token, types: types, @@ -1593,538 +1605,529 @@ global.prettydiff.csspretty = function csspretty_(options) { begin: begin }, definition: def - }, ""]; - } - return { - data : { - token: token, - types: types, - lines: lines, - depth: depth, - begin: begin - }, - definition: def - }; - }()); - } - - //analysis - if (options.mode === "analysis") { - return (function csspretty__summary() { - var summ = [], - inl = options.source.length, - out = output.length, - uris = uri.length, - uric = 0, - a = 0, - b = 0, - color = []; - (function csspretty_summary_colorNormalize() { - var aa = 0, - bb = 0, - cc = colors.length; - colors.sort(); - color.push(colors[0]); - for (aa = 0; aa < cc; aa += 1) { - if (colors[aa] !== color[bb]) { - color.push(colors[aa]); - bb += 1; - } - } + }; }()); - summ.push("

Number of HTTP requests: " + - ""); - summ.push(uris); - summ.push("

<" + - "th>Quantity
Component counts and sizes
Type NameCharacter Size
curly braces<" + - "/th>"); - summ.push(stats.braces); - summ.push(""); - summ.push(stats.braces); - summ.push("
colon"); - summ.push(stats.colon); - summ.push(""); - summ.push(stats.colon); - summ.push("
comments"); - summ.push(stats.comments.count); - summ.push(""); - summ.push(stats.comments.chars); - summ.push("
properties"); - summ.push(stats.properties.count); - summ.push(""); - summ.push(stats.properties.chars); - summ.push("
selectors"); - summ.push(stats.selectors.count); - summ.push(""); - summ.push(stats.selectors.chars); - summ.push("
semicolons"); - summ.push(stats.semi); - summ.push(""); - summ.push(stats.semi); - summ.push("
white space"); - summ.push(stats.space); - summ.push(""); - summ.push(stats.space); - summ.push("
values"); - summ.push(stats.values.count); - summ.push(""); - summ.push(stats.values.chars); - summ.push("
variables"); - summ.push(stats.variables.count); - summ.push(""); - summ.push(stats.variables.chars); - summ.push("
CSS character size change
I" + - "nput"); - summ.push(inl); - summ.push("
Output"); - summ.push(out); - summ.push("
"); - if (out > inl) { - summ.push("Increase"); - summ.push(out - inl); - summ.push("
Percent Change"); - a = (((out - inl) / out) * 100); - summ.push(a.toFixed(2)); - } else { - summ.push("Decrease"); - summ.push(inl - out); - summ.push("
Percent Change"); - a = (((inl - out) / inl) * 100); - summ.push(a.toFixed(2)); - } - summ.push("%
"); - for (a = 0; a < uris; a += 1) { - uric = 1; - for (b = a + 1; b < uris; b += 1) { - if (uri[a] === uri[b]) { - uric += 1; - uri.splice(b, 1); - uris -= 1; + } + + //analysis + if (options.mode === "analysis") { + return (function csspretty__summary() { + var summ = [], + inl = options.source.length, + out = output.length, + uris = uri.length, + uric = 0, + a = 0, + b = 0, + color = []; + (function csspretty_summary_colorNormalize() { + var aa = 0, + bb = 0, + cc = colors.length; + colors.sort(); + color.push(colors[0]); + for (aa = 0; aa < cc; aa += 1) { + if (colors[aa] !== color[bb]) { + color.push(colors[aa]); + bb += 1; + } } - } - summ.push("
A List of HTTP Requests
Quant" + - "ityURI
"); - summ.push(uric); + }()); + summ.push("

Number of HTTP requests: " + + ""); + summ.push(uris); + summ.push("

<" + + "th>Quantity"); - } - summ.push("
Component counts and sizes
Type NameCharacter Size
curly braces<" + + "/th>"); + summ.push(stats.braces); summ.push(""); - summ.push(uri[a].replace(/&/g, "&").replace(//g, ">")); - summ.push("
"); - summ.push("
"); - if (color.length === 0) { - summ.push("

0 colors were identified in the provided code.

"); - } else { - summ.push("

These "); - summ.push(color.length); - if (color.length > 1) { - summ.push(" different"); + summ.push(stats.braces); + summ.push("

colon"); + summ.push(stats.colon); + summ.push(""); + summ.push(stats.colon); + summ.push("
comments"); + summ.push(stats.comments.count); + summ.push(""); + summ.push(stats.comments.chars); + summ.push("
properties"); + summ.push(stats.properties.count); + summ.push(""); + summ.push(stats.properties.chars); + summ.push("
selectors"); + summ.push(stats.selectors.count); + summ.push(""); + summ.push(stats.selectors.chars); + summ.push("
semicolons"); + summ.push(stats.semi); + summ.push(""); + summ.push(stats.semi); + summ.push("
white space"); + summ.push(stats.space); + summ.push(""); + summ.push(stats.space); + summ.push("
values"); + summ.push(stats.values.count); + summ.push(""); + summ.push(stats.values.chars); + summ.push("
variables"); + summ.push(stats.variables.count); + summ.push(""); + summ.push(stats.variables.chars); + summ.push("
CSS character size change
I" + + "nput"); + summ.push(inl); + summ.push("
Output"); + summ.push(out); + summ.push("
"); + if (out > inl) { + summ.push("Increase"); + summ.push(out - inl); + summ.push("
Percent Change"); + a = (((out - inl) / out) * 100); + summ.push(a.toFixed(2)); + } else { + summ.push("Decrease"); + summ.push(inl - out); + summ.push("
Percent Change"); + a = (((inl - out) / inl) * 100); + summ.push(a.toFixed(2)); } - summ.push(" color"); - if (color.length > 1) { - summ.push("s"); + summ.push("%
"); + for (a = 0; a < uris; a += 1) { + uric = 1; + for (b = a + 1; b < uris; b += 1) { + if (uri[a] === uri[b]) { + uric += 1; + uri.splice(b, 1); + uris -= 1; + } + } + summ.push(""); } - summ.push(" were identified in the provided code:

"); - summ.push(color.join(", ")); - summ.push("

"); - if (options.accessibility === true) { - (function csspretty__summary_colorConvert() { - var vl = "", - bb = color.length, - aa = 0, - luminance = function csspretty__summary_colorConvert_luminance(rgb) { - var convert = function csspretty__summary_colorConvert_luminance_convert(x) { - if (x === 0) { - return 0; + summ.push("
A List of HTTP Requests
Quant" + + "ityURI
"); + summ.push(uric); + summ.push(""); + summ.push(uri[a].replace(/&/g, "&").replace(//g, ">")); + summ.push("
"); + summ.push("
"); + if (color.length === 0) { + summ.push("

0 colors were identified in the provided code.

"); + } else { + summ.push("

These "); + summ.push(color.length); + if (color.length > 1) { + summ.push(" different"); + } + summ.push(" color"); + if (color.length > 1) { + summ.push("s"); + } + summ.push(" were identified in the provided code:

"); + summ.push(color.join(", ")); + summ.push("

"); + if (options.accessibility === true) { + (function csspretty__summary_colorConvert() { + var vl = "", + bb = color.length, + aa = 0, + luminance = function csspretty__summary_colorConvert_luminance(rgb) { + var convert = function csspretty__summary_colorConvert_luminance_convert(x) { + if (x === 0) { + return 0; + } + x = (x / 255); + if ((x * 100000) <= 3928) { + return ((x * 100) / 1292) * 10000; + } + x *= 100000; + return Math.pow(((x + 5500) / 105500), 2.4) * 10000; + }; + return ((2126 * convert(rgb[0])) + (7152 * convert(rgb[1])) + (722 * convert(rgb[2]))) / 100000000; + }, + hexToDec = function csspretty__summary_colorConvert_hexToDec(val) { + var str = val + .slice(1) + .split(""), + rgb = [], + num = [], + aaa = 0, + bbb = str.length; + for (aaa = 0; aaa < bbb; aaa += 1) { + if (str[aaa] === "a") { + num.push(10); + } else if (str[aaa] === "b") { + num.push(11); + } else if (str[aaa] === "c") { + num.push(12); + } else if (str[aaa] === "d") { + num.push(13); + } else if (str[aaa] === "e") { + num.push(14); + } else if (str[aaa] === "f") { + num.push(15); + } else { + num.push(Number(str[aaa])); + } } - x = (x / 255); - if ((x * 100000) <= 3928) { - return ((x * 100) / 1292) * 10000; + if (bbb === 3) { + rgb.push((num[0] * 16) + num[0]); + rgb.push((num[1] * 16) + num[1]); + rgb.push((num[2] * 16) + num[2]); + } else { + rgb.push((num[0] * 16) + num[1]); + rgb.push((num[2] * 16) + num[3]); + rgb.push((num[4] * 16) + num[5]); } - x *= 100000; - return Math.pow(((x + 5500) / 105500), 2.4) * 10000; - }; - return ((2126 * convert(rgb[0])) + (7152 * convert(rgb[1])) + (722 * convert(rgb[2]))) / 100000000; - }, - hexToDec = function csspretty__summary_colorConvert_hexToDec(val) { - var str = val - .slice(1) - .split(""), - rgb = [], - num = [], - aaa = 0, - bbb = str.length; - for (aaa = 0; aaa < bbb; aaa += 1) { - if (str[aaa] === "a") { - num.push(10); - } else if (str[aaa] === "b") { - num.push(11); - } else if (str[aaa] === "c") { - num.push(12); - } else if (str[aaa] === "d") { - num.push(13); - } else if (str[aaa] === "e") { - num.push(14); - } else if (str[aaa] === "f") { - num.push(15); + return luminance(rgb); + }, + rgbToDec = function csspretty__summary_colorConvert_rgbToDec(val) { + var rgb = [], + rgbs = [], + rr = 0; + if (vl.charAt(3) === "a") { + vl = vl + .slice(5, vl.length - 1) + .replace(/\s+/g, ""); + rgbs = vl.split(","); + rgbs.pop(); } else { - num.push(Number(str[aaa])); + vl = vl + .slice(4, vl.length - 1) + .replace(/\s+/g, ""); + rgbs = vl.split(","); } - } - if (bbb === 3) { - rgb.push((num[0] * 16) + num[0]); - rgb.push((num[1] * 16) + num[1]); - rgb.push((num[2] * 16) + num[2]); - } else { - rgb.push((num[0] * 16) + num[1]); - rgb.push((num[2] * 16) + num[3]); - rgb.push((num[4] * 16) + num[5]); - } - return luminance(rgb); - }, - rgbToDec = function csspretty__summary_colorConvert_rgbToDec(val) { - var rgb = [], - rgbs = [], - rr = 0; - if (vl.charAt(3) === "a") { - vl = vl - .slice(5, vl.length - 1) - .replace(/\s+/g, ""); - rgbs = vl.split(","); - rgbs.pop(); - } else { - vl = vl - .slice(4, vl.length - 1) - .replace(/\s+/g, ""); - rgbs = vl.split(","); - } - do { - if ((/^([0-9a-f]{2})$/).test(rgbs[rr]) === false) { - if (rgbs[rr].charAt(rgbs[rr].length - 1) === "%") { - vl = rgbs[rr].slice(0, rgbs[rr].length - 1); - if (isNaN(vl) === true) { - return val; - } - rgb.push(Number(vl)); - if (rgb[rr] < 0) { - rgb[rr] = 0; - } else if (rgb[rr] > 100) { - rgb[rr] = 100; - } - rgb[rr] = Math.round(2.55 * rgb[rr]); - } else { - if (isNaN(rgbs[rr]) === true) { - return val; - } - rgb.push(Number(rgbs[rr])); - if (rgb[rr] < 0) { - rgb[rr] = 0; - } else if (rgb[rr] > 255) { - rgb[rr] = 255; + do { + if ((/^([0-9a-f]{2})$/).test(rgbs[rr]) === false) { + if (rgbs[rr].charAt(rgbs[rr].length - 1) === "%") { + vl = rgbs[rr].slice(0, rgbs[rr].length - 1); + if (isNaN(vl) === true) { + return val; + } + rgb.push(Number(vl)); + if (rgb[rr] < 0) { + rgb[rr] = 0; + } else if (rgb[rr] > 100) { + rgb[rr] = 100; + } + rgb[rr] = Math.round(2.55 * rgb[rr]); + } else { + if (isNaN(rgbs[rr]) === true) { + return val; + } + rgb.push(Number(rgbs[rr])); + if (rgb[rr] < 0) { + rgb[rr] = 0; + } else if (rgb[rr] > 255) { + rgb[rr] = 255; + } + rgb[rr] = Math.round(rgb[rr]); } - rgb[rr] = Math.round(rgb[rr]); } - } - rr += 1; - } while (rr < 3); - return luminance(rgb); - }; - colors = []; - for (aa = 0; aa < bb; aa += 1) { - if (color[aa] === undefined) { - break; - } - vl = color[aa].toLowerCase(); - if ((/^(#[0-9a-f]{3,6})$/).test(vl) === true) { - colors.push(hexToDec(vl.slice(1))); - } else if ((/^(rgba?\()/).test(vl) === true) { - colors.push(rgbToDec(vl)); - } else if (colorNames[vl] !== undefined) { - colors.push(colorNames[vl]); + rr += 1; + } while (rr < 3); + return luminance(rgb); + }; + colors = []; + for (aa = 0; aa < bb; aa += 1) { + if (color[aa] === undefined) { + break; + } + vl = color[aa].toLowerCase(); + if ((/^(#[0-9a-f]{3,6})$/).test(vl) === true) { + colors.push(hexToDec(vl.slice(1))); + } else if ((/^(rgba?\()/).test(vl) === true) { + colors.push(rgbToDec(vl)); + } else if (colorNames[vl] !== undefined) { + colors.push(colorNames[vl]); + } } - } - }()); + }()); + } } - } - if (options.nodeasync === true) { - return [summ.join(""), ""]; - } - return summ.join(""); - }()); - } + if (options.nodeasync === true) { + return [summ.join(""), ""]; + } + return summ.join(""); + }()); + } - //beautification - if (options.mode !== "minify") { - output = (function csspretty__beautify() { - var a = 0, - len = token.length, - build = [], - indent = options.inlevel, - mixin = false, - //a single unit of indentation - tab = (function csspretty__beautify_tab() { - var aa = 0, - bb = []; - for (aa = 0; aa < options.insize; aa += 1) { - bb.push(options.inchar); - } - return bb.join(""); - }()), - //new lines plus indentation - nl = function csspretty__beautify_nl(tabs) { - var aa = 0; - if (build[build.length - 1] === tab) { - do { - build.pop(); - } while (build[build.length - 1] === tab); - } - build.push(lf); - for (aa = 0; aa < tabs; aa += 1) { - build.push(tab); - } - }, - //breaks selector lists onto newlines - selector = function csspretty__beautify_selector(item) { - var aa = 0, - bb = 0, - cc = 0, - block = "", - items = [], - leng = item.length; - if (options.compressedcss === true && (/\)\s*when\s*\(/).test(item) === true) { - item = item.replace(/\)\s*when\s*\(/, ")" + lf + (function csspretty__beautify_selector_whenTab() { - var wtab = "", - aaa = indent + 1; + //beautification + if (options.mode !== "minify") { + output = (function csspretty__beautify() { + var a = 0, + len = token.length, + build = [], + indent = options.inlevel, + mixin = false, + //a single unit of indentation + tab = (function csspretty__beautify_tab() { + var aa = 0, + bb = []; + for (aa = 0; aa < options.insize; aa += 1) { + bb.push(options.inchar); + } + return bb.join(""); + }()), + //new lines plus indentation + nl = function csspretty__beautify_nl(tabs) { + var aa = 0; + if (build[build.length - 1] === tab) { do { - wtab += tab; - aaa -= 1; - } while (aaa > 0); - return wtab; - }()) + "when ("); - } - for (aa = 0; aa < leng; aa += 1) { - if (block === "") { - if (item.charAt(aa) === "\"") { - block = "\""; - bb += 1; - } else if (item.charAt(aa) === "'") { - block = "'"; - bb += 1; - } else if (item.charAt(aa) === "(") { - block = ")"; - bb += 1; - } else if (item.charAt(aa) === "[") { - block = "]"; - bb += 1; + build.pop(); + } while (build[build.length - 1] === tab); + } + build.push(lf); + for (aa = 0; aa < tabs; aa += 1) { + build.push(tab); + } + }, + //breaks selector lists onto newlines + selector = function csspretty__beautify_selector(item) { + var aa = 0, + bb = 0, + cc = 0, + block = "", + items = [], + leng = item.length; + if (options.compressedcss === true && (/\)\s*when\s*\(/).test(item) === true) { + item = item.replace(/\)\s*when\s*\(/, ")" + lf + (function csspretty__beautify_selector_whenTab() { + var wtab = "", + aaa = indent + 1; + do { + wtab += tab; + aaa -= 1; + } while (aaa > 0); + return wtab; + }()) + "when ("); + } + for (aa = 0; aa < leng; aa += 1) { + if (block === "") { + if (item.charAt(aa) === "\"") { + block = "\""; + bb += 1; + } else if (item.charAt(aa) === "'") { + block = "'"; + bb += 1; + } else if (item.charAt(aa) === "(") { + block = ")"; + bb += 1; + } else if (item.charAt(aa) === "[") { + block = "]"; + bb += 1; + } + } else if ((item.charAt(aa) === "(" && block === ")") || (item.charAt(aa) === "[" && block === "]")) { + bb += 1; + } else if (item.charAt(aa) === block) { + bb -= 1; + if (bb === 0) { + block = ""; + } } - } else if ((item.charAt(aa) === "(" && block === ")") || (item.charAt(aa) === "[" && block === "]")) { - bb += 1; - } else if (item.charAt(aa) === block) { - bb -= 1; - if (bb === 0) { - block = ""; + if (block === "" && item.charAt(aa) === ",") { + items.push(item.substring(cc, aa + 1)); + cc = aa + 1; } } - if (block === "" && item.charAt(aa) === ",") { - items.push(item.substring(cc, aa + 1)); - cc = aa + 1; + if (cc > 0) { + items.push(item.substr(cc)); } - } - if (cc > 0) { - items.push(item.substr(cc)); - } - leng = items.length; - if (leng === 0) { - items.push(item); - } - if (options.selectorlist === true) { - build.push(items.join(" ")); - } else { - build.push(items[0].replace(/,(\s*)/g, ", ").replace(/(,\ )$/, ",")); - for (aa = 1; aa < leng; aa += 1) { - nl(indent); - build.push(items[aa].replace(/,(\s*)/g, ", ").replace(/(,\ )$/, ",")); + leng = items.length; + if (leng === 0) { + items.push(item); } - } - if (options.compressedcss === false) { - build.push(" "); - } - }; - if (options.inlevel > 0) { - a = options.inlevel; - do { - a -= 1; - build.push(tab); - } while (a > 0); - } - - //beautification loop - for (a = 0; a < len; a += 1) { - if (lines[a] > 1 && options.compressedcss === false && (types[a] === "start" || types[a] === "end" || types[a] === "selector" || types[a] === "comment" || types[a] === "property" || types[a] === "propvar" || types[a].indexOf("external") > -1)) { - if (options.cssinsertlines === true && types[a] === "selector" && types[a - 1] !== "comment") { - lines[a] -= 1; - } - if (build[build.length - 1] === tab) { - do { - build.pop(); - } while (build[build.length - 1] === tab); - } - if (lines[a] > 1) { - if (lines[a] > 2) { - do { - lines[a] -= 1; - build.push(lf); - } while (lines[a] > 2); + if (options.selectorlist === true) { + build.push(items.join(" ")); + } else { + build.push(items[0].replace(/,(\s*)/g, ", ").replace(/(,\ )$/, ",")); + for (aa = 1; aa < leng; aa += 1) { + nl(indent); + build.push(items[aa].replace(/,(\s*)/g, ", ").replace(/(,\ )$/, ",")); + } } - nl(indent); - } + if (options.compressedcss === false) { + build.push(" "); + } + }; + if (options.inlevel > 0) { + a = options.inlevel; + do { + a -= 1; + build.push(tab); + } while (a > 0); } - if (types[a] === "start") { - if (types[a - 1] === "propvar" && options.compressedcss === false) { - build.push(" "); - } - if (a > 0 && token[a - 1].charAt(token[a - 1].length - 1) === "#") { - build.push(token[a]); - } else { - if (options.braces === true) { - if (build[build.length - 1] === " ") { + + //beautification loop + for (a = 0; a < len; a += 1) { + if (lines[a] > 1 && options.compressedcss === false && (types[a] === "start" || types[a] === "end" || types[a] === "selector" || types[a] === "comment" || types[a] === "property" || types[a] === "propvar" || types[a].indexOf("external") > -1)) { + if (options.cssinsertlines === true && types[a] === "selector" && types[a - 1] !== "comment") { + lines[a] -= 1; + } + if (build[build.length - 1] === tab) { + do { build.pop(); + } while (build[build.length - 1] === tab); + } + if (lines[a] > 1) { + if (lines[a] > 2) { + do { + lines[a] -= 1; + build.push(lf); + } while (lines[a] > 2); } nl(indent); - } else if (types[a - 1] === "colon") { + } + } + if (types[a] === "start") { + if (types[a - 1] === "propvar" && options.compressedcss === false) { build.push(" "); } - build.push(token[a]); - indent += 1; - if (types[a + 1] !== "end" && (options.compressedcss === false || (options.compressedcss === true && types[a + 1] === "start")) && (types[a + 1] !== "selector" || options.cssinsertlines === false)) { - nl(indent); + if (a > 0 && token[a - 1].charAt(token[a - 1].length - 1) === "#") { + build.push(token[a]); + } else { + if (options.braces === true) { + if (build[build.length - 1] === " ") { + build.pop(); + } + nl(indent); + } else if (types[a - 1] === "colon") { + build.push(" "); + } + build.push(token[a]); + indent += 1; + if (types[a + 1] !== "end" && (options.compressedcss === false || (options.compressedcss === true && types[a + 1] === "start")) && (types[a + 1] !== "selector" || options.cssinsertlines === false)) { + nl(indent); + } } - } - } else if (types[a] === "end") { - if (mixin === true) { - mixin = false; - build.push(token[a]); - build.push(" "); - } else { - indent -= 1; - if (types[a - 1] !== "start" && options.compressedcss === false) { + } else if (types[a] === "end") { + if (mixin === true) { + mixin = false; + build.push(token[a]); + build.push(" "); + } else { + indent -= 1; + if (types[a - 1] !== "start" && options.compressedcss === false) { + nl(indent); + } + build.push(token[a]); + if (options.compressedcss === true && types[a + 1] === "end") { + nl(indent - 1); + } else if (options.cssinsertlines === true && types[a + 1] === "selector" && lines[a] < 2 && token[a - 1] !== "{") { + build.push(lf); + } else if (types[a + 1] !== "end" && types[a + 1] !== "semi" && types[a + 1] !== "comment") { + nl(indent); + } + } + } else if (types[a] === "semi") { + if (token[a] !== "x;" && (options.compressedcss === false || (options.compressedcss === true && types[a + 1] !== "end"))) { + build.push(token[a]); + } + if (types[a + 1] === "comment-inline") { + build.push(" "); + } else if (types[a + 1] !== "end" && types[a + 1] !== "comment" && options.compressedcss === false) { + if (options.cssinsertlines === true && types[a + 1] === "selector") { + build.push(lf); + } else if (lines[a + 1] > 0 || (types[a + 1] !== undefined && types[a + 1].indexOf("external") < 0)) { + nl(indent); + } + } + } else if (types[a] === "selector") { + if (a > 0 && types[a - 1] !== "comment" && (options.cssinsertlines === true || (options.compressedcss === true && (types[a - 1] === "start" || types[a - 1] === "semi")))) { nl(indent); } - build.push(token[a]); - if (options.compressedcss === true && types[a + 1] === "end") { - nl(indent - 1); - } else if (options.cssinsertlines === true && types[a + 1] === "selector" && lines[a] < 2 && token[a - 1] !== "{") { + if (token[a].charAt(token[a].length - 1) === "#") { + build.push(token[a]); + mixin = true; + } else if (token[a].indexOf(",") > -1) { + selector(token[a]); + } else { + if (token[a].charAt(0) === ":" && token[a - 1] === "}" && build[build.length - 1] === " ") { + build.pop(); + } + build.push(token[a]); + if (options.compressedcss === false) { + build.push(" "); + } + } + } else if ((types[a] === "comment" || types[a] === "comment-inline") && types[a - 1] !== "colon" && types[a - 1] !== "property") { + if (types[a - 1] === "value" && types[a] === "comment-inline") { + build.push(" "); + } + if (a > 0 && options.compressedcss === true && types[a] === "comment" && types[a - 1] !== "comment") { build.push(lf); - } else if (types[a + 1] !== "end" && types[a + 1] !== "semi" && types[a + 1] !== "comment") { + nl(indent); + } else if (a > 0 && types[a - 1] !== "start" && types[a] !== "comment-inline") { nl(indent); } - } - } else if (types[a] === "semi") { - if (token[a] !== "x;" && (options.compressedcss === false || (options.compressedcss === true && types[a + 1] !== "end"))) { build.push(token[a]); - } - if (types[a + 1] === "comment-inline") { - build.push(" "); - } else if (types[a + 1] !== "end" && types[a + 1] !== "comment" && options.compressedcss === false) { - if (options.cssinsertlines === true && types[a + 1] === "selector") { - build.push(lf); - } else if (lines[a + 1] > 0 || (types[a + 1] !== undefined && types[a + 1].indexOf("external") < 0)) { + if (types[a + 1] !== "end" && types[a + 1] !== "comment") { nl(indent); } - } - } else if (types[a] === "selector") { - if (a > 0 && types[a - 1] !== "comment" && (options.cssinsertlines === true || (options.compressedcss === true && (types[a - 1] === "start" || types[a - 1] === "semi")))) { - nl(indent); - } - if (token[a].charAt(token[a].length - 1) === "#") { - build.push(token[a]); - mixin = true; - } else if (token[a].indexOf(",") > -1) { - selector(token[a]); } else { - if (token[a].charAt(0) === ":" && token[a - 1] === "}" && build[build.length - 1] === " ") { - build.pop(); - } - build.push(token[a]); - if (options.compressedcss === false) { - build.push(" "); - } - } - } else if ((types[a] === "comment" || types[a] === "comment-inline") && types[a - 1] !== "colon" && types[a - 1] !== "property") { - if (types[a - 1] === "value" && types[a] === "comment-inline") { - build.push(" "); - } - if (a > 0 && options.compressedcss === true && types[a] === "comment" && types[a - 1] !== "comment") { - build.push(lf); - nl(indent); - } else if (a > 0 && types[a - 1] !== "start" && types[a] !== "comment-inline") { - nl(indent); - } - build.push(token[a]); - if (types[a + 1] !== "end" && types[a + 1] !== "comment") { - nl(indent); - } - } else { - if (types[a - 1] !== "semi" && options.compressedcss === false && (mixin === false || token[a - 1] === ":") && token[a - 2] !== "filter" && token[a - 2] !== "progid") { - if (types[a] === "value" || (types[a].indexOf("external") > -1 && types[a - 1] === "colon")) { - build.push(" "); + if (types[a - 1] !== "semi" && options.compressedcss === false && (mixin === false || token[a - 1] === ":") && token[a - 2] !== "filter" && token[a - 2] !== "progid") { + if (types[a] === "value" || (types[a].indexOf("external") > -1 && types[a - 1] === "colon")) { + build.push(" "); + } + } else if (options.compressedcss === true && (types[a] === "value" || types[a] === "propvar")) { + token[a] = token[a].replace(/(\s*,\s*)/g, ","); } - } else if (options.compressedcss === true && (types[a] === "value" || types[a] === "propvar")) { - token[a] = token[a].replace(/(\s*,\s*)/g, ","); - } - if (types[a] === "external_start") { - indent += 1; - } else if (types[a] === "external_end") { - indent -= 1; - if (build[build.length - 1] === tab) { + if (types[a] === "external_start") { + indent += 1; + } else if (types[a] === "external_end") { + indent -= 1; + if (build[build.length - 1] === tab) { + build.pop(); + } + } else if (types[a] === "external_else" && build[build.length - 1] === tab) { build.pop(); } - } else if (types[a] === "external_else" && build[build.length - 1] === tab) { - build.pop(); - } - build.push(token[a]); - if (types[a].indexOf("external") > -1 && types[a + 1] !== "semi") { - if ((types[a + 1] !== undefined && types[a + 1].indexOf("external") > -1) || (lines[a + 1] === 1 && types[a + 1] !== "end") || lines[a + 1] > 1) { - nl(indent); + build.push(token[a]); + if (types[a].indexOf("external") > -1 && types[a + 1] !== "semi") { + if ((types[a + 1] !== undefined && types[a + 1].indexOf("external") > -1) || (lines[a + 1] === 1 && types[a + 1] !== "end") || lines[a + 1] > 1) { + nl(indent); + } } } } - } - if (options.preserve > 0 && (lines[lines.length - 1] > 0 || endline === true)) { + if (options.preserve > 0 && (lines[lines.length - 1] > 0 || endline === true)) { + return build + .join("") + .replace(/(\s+)$/, lf); + } return build .join("") - .replace(/(\s+)$/, lf); - } - return build + .replace(/(\s+)$/, ""); + }()); + } else { + output = token .join("") - .replace(/(\s+)$/, ""); - }()); + .replace(/;\}/g, "}"); + } + if (options.nodeasync === true) { + return [output, ""]; + } + return output; + }; + if (typeof module === "object" && typeof module.parent === "object") { + //commonjs and nodejs support + module.exports = csspretty; + } else if ((typeof define === "object" || typeof define === "function") && (typeof ace !== "object" || ace.prettydiffid === undefined)) { + //requirejs support + define(function requirejs(require, module) { + module.exports = csspretty; + //worthless if block to appease RequireJS and JSLint + if (typeof require === "number") { + return require; + } + return function requirejs_csspretty_module(x) { + return csspretty(x); + }; + }); } else { - output = token - .join("") - .replace(/;\}/g, "}"); - } - if (options.nodeasync === true) { - return [output, ""]; + global.prettydiff.csspretty = csspretty; } - return output; -}; -if (typeof module === "object" && typeof module.parent === "object") { - //commonjs and nodejs support - module.exports = global.prettydiff.csspretty; -} else if ((typeof define === "object" || typeof define === "function") && (typeof ace !== "object" || ace.prettydiffid === undefined)) { - //requirejs support - define(function requirejs(require, module) { - "use strict"; - module.exports = global.prettydiff.csspretty; - //worthless if block to appease RequireJS and JSLint - if (typeof require === "number") { - return require; - } - return function requirejs_csspretty_module(x) { - global.prettydiff.csspretty(x); - }; - }); -} +}()); diff --git a/lib/csvpretty.js b/lib/csvpretty.js index 06a40cc0..47c89a59 100644 --- a/lib/csvpretty.js +++ b/lib/csvpretty.js @@ -8,99 +8,101 @@ http://mailmarkup.org/ http://prettydiff.com/ **********************************************************************/ -global.prettydiff.csvpretty = function csvpretty_(options) { +(function () { "use strict"; - var token = []; - options.csvchar = (typeof options.csvchar === "string") - ? options.csvchar - : ","; - options.source = (typeof options.source !== "string" || options.source === "" || (/^(\s+)$/).test(options.source) === true) - ? "Error: no source supplied to csvpretty." - : options.source.replace(/\r\n/g, "\n").replace(/\r/g, "\n"); - (function csvpretty__tokenize() { - var input = options.source.split(""), - d = options.csvchar.length, - e = 0, - cell = [], - row = [], - quote = false, - cellCrunch = function csvpretty__tokenize_cellCrunch() { - var str = cell.join(""); - cell = []; - if (str !== "") { - row.push(str); - } - }, - parse = function csvpretty__tokenize_parse(item, index, arr) { - if (quote === false) { - if (cell.length === 0 && item === "\"" && (arr[index + 1] !== "\"" || arr[index + 2] === "\"")) { - quote = true; - } else if (item === "\"" && arr[index + 1] === "\"") { - cell.push("\""); - arr[index + 1] = ""; - } else if (item === "\n") { - cellCrunch(); - token.push(row); - row = []; - } else if (item === options.csvchar.charAt(0)) { - if (d === 1) { + var csvpretty = function csvpretty_(options) { + var token = []; + options.csvchar = (typeof options.csvchar === "string") + ? options.csvchar + : ","; + options.source = (typeof options.source !== "string" || options.source === "" || (/^(\s+)$/).test(options.source) === true) + ? "Error: no source supplied to csvpretty." + : options.source.replace(/\r\n/g, "\n").replace(/\r/g, "\n"); + (function csvpretty__tokenize() { + var input = options.source.split(""), + d = options.csvchar.length, + e = 0, + cell = [], + row = [], + quote = false, + cellCrunch = function csvpretty__tokenize_cellCrunch() { + var str = cell.join(""); + cell = []; + if (str !== "") { + row.push(str); + } + }, + parse = function csvpretty__tokenize_parse(item, index, arr) { + if (quote === false) { + if (cell.length === 0 && item === "\"" && (arr[index + 1] !== "\"" || arr[index + 2] === "\"")) { + quote = true; + } else if (item === "\"" && arr[index + 1] === "\"") { + cell.push("\""); + arr[index + 1] = ""; + } else if (item === "\n") { cellCrunch(); - } else { - e = 0; - do { - e += 1; - } while (e < d && arr[index + e] === options.csvchar.charAt(e)); - if (e === d) { + token.push(row); + row = []; + } else if (item === options.csvchar.charAt(0)) { + if (d === 1) { cellCrunch(); - e = 1; + } else { + e = 0; do { - arr[index + e] = ""; e += 1; - } while (e < d); - } else if (item !== "") { - cell.push(item); + } while (e < d && arr[index + e] === options.csvchar.charAt(e)); + if (e === d) { + cellCrunch(); + e = 1; + do { + arr[index + e] = ""; + e += 1; + } while (e < d); + } else if (item !== "") { + cell.push(item); + } } + } else if (item !== "") { + cell.push(item); } - } else if (item !== "") { + } else if (item !== "\"" && item !== "") { cell.push(item); + } else if (item === "\"" && arr[index + 1] === "\"") { + cell.push("\""); + arr[index + 1] = ""; + } else if (item === "\"") { + cellCrunch(); + quote = false; } - } else if (item !== "\"" && item !== "") { - cell.push(item); - } else if (item === "\"" && arr[index + 1] === "\"") { - cell.push("\""); - arr[index + 1] = ""; - } else if (item === "\"") { - cellCrunch(); - quote = false; - } - }; - input.forEach(parse); - if (cell.length > 0) { - cellCrunch(); - token.push(row); - } - }()); - return token; -}; -if (typeof module === "object" && typeof module.parent === "object") { - //commonjs and nodejs support - module.exports = function commonjs_csvpretty(x) { - "use strict"; - return global.prettydiff.csvpretty(x); + }; + input.forEach(parse); + if (cell.length > 0) { + cellCrunch(); + token.push(row); + } + }()); + return token; }; -} else if ((typeof define === "object" || typeof define === "function") && (typeof ace !== "object" || ace.prettydiffid === undefined)) { - //requirejs support - define(function requirejs(require, module) { - "use strict"; - module.exports = function requirejs_csvpretty_export(x) { - return global.prettydiff.csvpretty(x); + if (typeof module === "object" && typeof module.parent === "object") { + //commonjs and nodejs support + module.exports = function commonjs_csvpretty(x) { + return csvpretty(x); }; - //worthless if block to appease RequireJS and JSLint - if (typeof require === "number") { - return require; - } - return function requirejs_csvpretty_module(x) { - global.prettydiff.csvpretty(x); - }; - }); -} + } else if ((typeof define === "object" || typeof define === "function") && (typeof ace !== "object" || ace.prettydiffid === undefined)) { + //requirejs support + define(function requirejs(require, module) { + module.exports = function requirejs_csvpretty_export(x) { + return csvpretty(x); + }; + //worthless if block to appease RequireJS and JSLint + if (typeof require === "number") { + return require; + } + return function requirejs_csvpretty_module(x) { + return csvpretty(x); + }; + }); + } else { + global.prettydiff.csvpretty = csvpretty; + } +}()); diff --git a/lib/diffview.js b/lib/diffview.js index 72c7c70b..f38fbdcf 100644 --- a/lib/diffview.js +++ b/lib/diffview.js @@ -45,852 +45,971 @@ * total error count when added to the next index * 3) Number of error lines in the HTML table */ -global.prettydiff.diffview = function diffview_(options) { +(function () { "use strict"; - (function diffview__options() { - options.diff = (typeof options.diff === "string") - ? options - .diff - .replace(options.functions.binaryCheck, "") - .replace(/\r\n?/g, "\n") - : ""; - options.source = (typeof options.source === "string") - ? options - .source - .replace(options.functions.binaryCheck, "") - .replace(/\r\n?/g, "\n") - : ""; - }()); + var diffview = function diffview_(options) { + (function diffview__options() { + options.diff = (typeof options.diff === "string") + ? options + .diff + .replace(options.functions.binaryCheck, "") + .replace(/\r\n?/g, "\n") + : ""; + options.source = (typeof options.source === "string") + ? options + .source + .replace(options.functions.binaryCheck, "") + .replace(/\r\n?/g, "\n") + : ""; + }()); - //diffview application contains three primary parts - //1. opcodes - performs the 'largest common subsequence' - // calculation to determine which lines are different. I - // did not write this logic. I have rewritten it for - // performance, but original logic is still intact. - //2. charcomp - performs the 'largest common subsequence' upon - // characters of two compared lines. - //3. The construction of the output into the 'node' array - //errorout is a count of differences - var errorout = 0, - //diffline is a count of lines that are not equal - diffline = 0, - //tab is a construct of a standard indentation for code - tab = (function diffview__tab() { - var a = 0, - output = []; - if (options.inchar === "") { - return ""; - } - for (a = 0; a < options.insize; a += 1) { - output.push(options.inchar); - } - return output.join(""); - }()), - //translates source code from a string to an array by - //splitting on line breaks - stringAsLines = function diffview__stringAsLines(str) { - var lines = (options.diffcli === true) - ? str - : str - .replace(/&/g, "&") - .replace(/&#lt;/g, "$#lt;") - .replace(/&#gt;/g, "$#gt;") - .replace(//g, "$#gt;"); - return lines.split("\n"); - }, - //array representation of base source - baseTextArray = stringAsLines(options.source), - //array representation of new source - newTextArray = stringAsLines(options.diff), - //the core algorithm. This logic is not mine even though I - //have largely rewritten it for performance. It determines - //the largest common subsequence calculations between lines - //of code - opcodes = (function diffview__opcodes() { - var junkdict = {}, - isbjunk = function diffview__opcodes_isbjunk(key) { - if (junkdict.hasOwnProperty(key)) { - return junkdict[key]; - } - }, - sourceFirst = [], - sourceSecond = [], - secondInContext = [], - reverse = false, - matching_blocks = [], - answer = [], - get_matching_blocks = function diffview__opcodes_getMatchingBlocks() { - var a = 0, - matchingLen = 0, - lowFirst = 0, - highFirst = 0, - lowSecond = 0, - highSecond = 0, - bestLongestFirst = 0, - bestLongestSecond = 0, - bestLongestSize = 0, - matchFirstPrior = 0, - matchFirstNew = 0, - matchSecondPrior = 0, - matchSecondNew = 0, - matchSizePrior = 0, - matchSizeNew = 0, - sourceFirstLength = sourceFirst.length, - sourceSecondLength = sourceSecond.length, - matchInstance = [], - queueInstance = [], - non_adjacent = [], - queue = [ - [0, sourceFirstLength, 0, sourceSecondLength] - ], - matchingSort = function diffview__opcodes_getMatchingBlocks_ntuplecomp(x, y) { - var b = 0, - end = Math.max(x.length, y.length); - for (b = 0; b < end; b += 1) { - if (x[b] < y[b]) { - return -1; - } - if (x[b] > y[b]) { - return 1; - } - } - return (x.length === y.length) - ? 0 - : ((x.length < y.length) - ? -1 - : 1); - }, - find_longest_match = function diffview__opcodes_getMatchingBlocks_findLongestMatch(lowFirst, highFirst, lowSecond, highSecond) { - var b = 0, - c = 0, - sContextLength = secondInContext.length, - sContextCompareLine = 0, - distance = 0, - priorLine = [ - 0, 0 - ], - bestFirst = lowFirst, - bestSecond = lowSecond, - bestsize = 0; - for (b = lowFirst; b < highFirst; b += 1) { - for (c = 0; c < sContextLength; c += 1) { - if (secondInContext[c][1] === sourceFirst[b]) { - if (sourceFirst[b] !== sourceSecond[b] || b === highFirst - 1 || sourceFirst[b + 1] === sourceSecond[b + 1]) { - sContextCompareLine = secondInContext[c][0]; - break; - } + //diffview application contains three primary parts + //1. opcodes - performs the 'largest common subsequence' + // calculation to determine which lines are different. I + // did not write this logic. I have rewritten it for + // performance, but original logic is still intact. + //2. charcomp - performs the 'largest common subsequence' upon + // characters of two compared lines. + //3. The construction of the output into the 'node' array + //errorout is a count of differences + var errorout = 0, + //diffline is a count of lines that are not equal + diffline = 0, + //tab is a construct of a standard indentation for code + tab = (function diffview__tab() { + var a = 0, + output = []; + if (options.inchar === "") { + return ""; + } + for (a = 0; a < options.insize; a += 1) { + output.push(options.inchar); + } + return output.join(""); + }()), + //translates source code from a string to an array by + //splitting on line breaks + stringAsLines = function diffview__stringAsLines(str) { + var lines = (options.diffcli === true) + ? str + : str + .replace(/&/g, "&") + .replace(/&#lt;/g, "$#lt;") + .replace(/&#gt;/g, "$#gt;") + .replace(//g, "$#gt;"); + return lines.split("\n"); + }, + //array representation of base source + baseTextArray = stringAsLines(options.source), + //array representation of new source + newTextArray = stringAsLines(options.diff), + //the core algorithm. This logic is not mine even though I + //have largely rewritten it for performance. It determines + //the largest common subsequence calculations between lines + //of code + opcodes = (function diffview__opcodes() { + var junkdict = {}, + isbjunk = function diffview__opcodes_isbjunk(key) { + if (junkdict.hasOwnProperty(key)) { + return junkdict[key]; + } + }, + sourceFirst = [], + sourceSecond = [], + secondInContext = [], + reverse = false, + matching_blocks = [], + answer = [], + get_matching_blocks = function diffview__opcodes_getMatchingBlocks() { + var a = 0, + matchingLen = 0, + lowFirst = 0, + highFirst = 0, + lowSecond = 0, + highSecond = 0, + bestLongestFirst = 0, + bestLongestSecond = 0, + bestLongestSize = 0, + matchFirstPrior = 0, + matchFirstNew = 0, + matchSecondPrior = 0, + matchSecondNew = 0, + matchSizePrior = 0, + matchSizeNew = 0, + sourceFirstLength = sourceFirst.length, + sourceSecondLength = sourceSecond.length, + matchInstance = [], + queueInstance = [], + non_adjacent = [], + queue = [ + [0, sourceFirstLength, 0, sourceSecondLength] + ], + matchingSort = function diffview__opcodes_getMatchingBlocks_ntuplecomp(x, y) { + var b = 0, + end = Math.max(x.length, y.length); + for (b = 0; b < end; b += 1) { + if (x[b] < y[b]) { + return -1; + } + if (x[b] > y[b]) { + return 1; } } - if (c !== sContextLength) { - if (sContextCompareLine >= lowSecond) { - if (sContextCompareLine >= highSecond) { - break; - } - if (priorLine[0] === sContextCompareLine - 1) { - distance = priorLine[1] + 1; - } else { - distance = 1; + return (x.length === y.length) + ? 0 + : ((x.length < y.length) + ? -1 + : 1); + }, + find_longest_match = function diffview__opcodes_getMatchingBlocks_findLongestMatch(lowFirst, highFirst, lowSecond, highSecond) { + var b = 0, + c = 0, + sContextLength = secondInContext.length, + sContextCompareLine = 0, + distance = 0, + priorLine = [ + 0, 0 + ], + bestFirst = lowFirst, + bestSecond = lowSecond, + bestsize = 0; + for (b = lowFirst; b < highFirst; b += 1) { + for (c = 0; c < sContextLength; c += 1) { + if (secondInContext[c][1] === sourceFirst[b]) { + if (sourceFirst[b] !== sourceSecond[b] || b === highFirst - 1 || sourceFirst[b + 1] === sourceSecond[b + 1]) { + sContextCompareLine = secondInContext[c][0]; + break; + } } - if (distance > bestsize) { - bestFirst = b - distance + 1; - bestSecond = sContextCompareLine - distance + 1; - bestsize = distance; + } + if (c !== sContextLength) { + if (sContextCompareLine >= lowSecond) { + if (sContextCompareLine >= highSecond) { + break; + } + if (priorLine[0] === sContextCompareLine - 1) { + distance = priorLine[1] + 1; + } else { + distance = 1; + } + if (distance > bestsize) { + bestFirst = b - distance + 1; + bestSecond = sContextCompareLine - distance + 1; + bestsize = distance; + } } + priorLine = [sContextCompareLine, distance]; } - priorLine = [sContextCompareLine, distance]; + } + while (bestFirst > lowFirst && bestSecond > lowSecond && isbjunk(sourceSecond[bestSecond - 1]) === undefined && sourceFirst[bestFirst - 1] === sourceSecond[bestSecond - 1]) { + bestFirst -= 1; + bestSecond -= 1; + bestsize += 1; + } + while (bestFirst + bestsize < highFirst && bestSecond + bestsize < highSecond && isbjunk(sourceSecond[bestSecond + bestsize]) === undefined && sourceFirst[bestFirst + bestsize] === sourceSecond[bestSecond + bestsize]) { + bestsize += 1; + } + while (bestFirst > lowFirst && bestSecond > lowSecond && isbjunk(sourceSecond[bestSecond - 1]) !== undefined && sourceFirst[bestFirst - 1] === sourceSecond[bestSecond - 1]) { + bestFirst -= 1; + bestSecond -= 1; + bestsize += 1; + } + while (bestFirst + bestsize < highFirst && bestSecond + bestsize < highSecond && isbjunk(sourceSecond[bestSecond + bestsize]) !== undefined && sourceFirst[bestFirst + bestsize] === sourceSecond[bestSecond + bestsize]) { + bestsize += 1; + } + return [bestFirst, bestSecond, bestsize]; + }; + while (queue.length > 0) { + queueInstance = queue.pop(); + lowFirst = queueInstance[0]; + highFirst = queueInstance[1]; + lowSecond = queueInstance[2]; + highSecond = queueInstance[3]; + matchInstance = find_longest_match(lowFirst, highFirst, lowSecond, highSecond); + bestLongestFirst = matchInstance[0]; + bestLongestSecond = matchInstance[1]; + bestLongestSize = matchInstance[2]; + if (bestLongestSize > 0) { + matching_blocks.push(matchInstance); + if (lowFirst < bestLongestFirst && lowSecond < bestLongestSecond) { + queue.push([lowFirst, bestLongestFirst, lowSecond, bestLongestSecond]); + } + if (bestLongestFirst + bestLongestSize < highFirst && bestLongestSecond + bestLongestSize < highSecond) { + queue.push([ + bestLongestFirst + bestLongestSize, + highFirst, + bestLongestSecond + bestLongestSize, + highSecond + ]); } } - while (bestFirst > lowFirst && bestSecond > lowSecond && isbjunk(sourceSecond[bestSecond - 1]) === undefined && sourceFirst[bestFirst - 1] === sourceSecond[bestSecond - 1]) { - bestFirst -= 1; - bestSecond -= 1; - bestsize += 1; - } - while (bestFirst + bestsize < highFirst && bestSecond + bestsize < highSecond && isbjunk(sourceSecond[bestSecond + bestsize]) === undefined && sourceFirst[bestFirst + bestsize] === sourceSecond[bestSecond + bestsize]) { - bestsize += 1; - } - while (bestFirst > lowFirst && bestSecond > lowSecond && isbjunk(sourceSecond[bestSecond - 1]) !== undefined && sourceFirst[bestFirst - 1] === sourceSecond[bestSecond - 1]) { - bestFirst -= 1; - bestSecond -= 1; - bestsize += 1; - } - while (bestFirst + bestsize < highFirst && bestSecond + bestsize < highSecond && isbjunk(sourceSecond[bestSecond + bestsize]) !== undefined && sourceFirst[bestFirst + bestsize] === sourceSecond[bestSecond + bestsize]) { - bestsize += 1; - } - return [bestFirst, bestSecond, bestsize]; - }; - while (queue.length > 0) { - queueInstance = queue.pop(); - lowFirst = queueInstance[0]; - highFirst = queueInstance[1]; - lowSecond = queueInstance[2]; - highSecond = queueInstance[3]; - matchInstance = find_longest_match(lowFirst, highFirst, lowSecond, highSecond); - bestLongestFirst = matchInstance[0]; - bestLongestSecond = matchInstance[1]; - bestLongestSize = matchInstance[2]; - if (bestLongestSize > 0) { - matching_blocks.push(matchInstance); - if (lowFirst < bestLongestFirst && lowSecond < bestLongestSecond) { - queue.push([lowFirst, bestLongestFirst, lowSecond, bestLongestSecond]); - } - if (bestLongestFirst + bestLongestSize < highFirst && bestLongestSecond + bestLongestSize < highSecond) { - queue.push([ - bestLongestFirst + bestLongestSize, - highFirst, - bestLongestSecond + bestLongestSize, - highSecond - ]); + } + matching_blocks.sort(matchingSort); + matchingLen = matching_blocks.length; + for (a = 0; a < matchingLen; a += 1) { + matchFirstNew = matching_blocks[a][0]; + matchSecondNew = matching_blocks[a][1]; + matchSizeNew = matching_blocks[a][2]; + if (matchFirstPrior + matchSizePrior === matchFirstNew && matchSecondPrior + matchSizePrior === matchSecondNew) { + matchSizePrior += matchSizeNew; + } else { + if (matchSizePrior > 0) { + non_adjacent.push([matchFirstPrior, matchSecondPrior, matchSizePrior]); + } + matchFirstPrior = matchFirstNew; + matchSecondPrior = matchSecondNew; + matchSizePrior = matchSizeNew; } } - } - matching_blocks.sort(matchingSort); - matchingLen = matching_blocks.length; - for (a = 0; a < matchingLen; a += 1) { - matchFirstNew = matching_blocks[a][0]; - matchSecondNew = matching_blocks[a][1]; - matchSizeNew = matching_blocks[a][2]; - if (matchFirstPrior + matchSizePrior === matchFirstNew && matchSecondPrior + matchSizePrior === matchSecondNew) { - matchSizePrior += matchSizeNew; + if (matchSizePrior > 0) { + non_adjacent.push([matchFirstPrior, matchSecondPrior, matchSizePrior]); + } + non_adjacent.push([sourceFirstLength, sourceSecondLength, 0]); + return non_adjacent; + }; + if (options.source === "" || options.diff === "") { + return ""; + } + (function diffview__opcodes_diffArray() { + (function diffview__opcodes_diffArray_determineReverse() { + if (baseTextArray.length > newTextArray.length) { + reverse = true; + sourceFirst = newTextArray; + sourceSecond = baseTextArray; } else { - if (matchSizePrior > 0) { - non_adjacent.push([matchFirstPrior, matchSecondPrior, matchSizePrior]); - } - matchFirstPrior = matchFirstNew; - matchSecondPrior = matchSecondNew; - matchSizePrior = matchSizeNew; + sourceFirst = baseTextArray; + sourceSecond = newTextArray; } - } - if (matchSizePrior > 0) { - non_adjacent.push([matchFirstPrior, matchSecondPrior, matchSizePrior]); - } - non_adjacent.push([sourceFirstLength, sourceSecondLength, 0]); - return non_adjacent; - }; - if (options.source === "" || options.diff === "") { - return ""; - } - (function diffview__opcodes_diffArray() { - (function diffview__opcodes_diffArray_determineReverse() { - if (baseTextArray.length > newTextArray.length) { - reverse = true; - sourceFirst = newTextArray; - sourceSecond = baseTextArray; - } else { - sourceFirst = baseTextArray; - sourceSecond = newTextArray; - } - }()); - (function diffview__opcodes_diffArray_clarity() { - var a = 0, - b = 0, - sourceLine = "", - ssLen = sourceSecond.length; - for (a = 0; a < ssLen; a += 1) { - sourceLine = sourceSecond[a]; - for (b = secondInContext.length - 1; b > -1; b -= 1) { - if (secondInContext[b][1] === sourceLine) { - break; + }()); + (function diffview__opcodes_diffArray_clarity() { + var a = 0, + b = 0, + sourceLine = "", + ssLen = sourceSecond.length; + for (a = 0; a < ssLen; a += 1) { + sourceLine = sourceSecond[a]; + for (b = secondInContext.length - 1; b > -1; b -= 1) { + if (secondInContext[b][1] === sourceLine) { + break; + } } - } - if (b > -1) { - if (ssLen >= 200 && 100 > ssLen) { - secondInContext.splice(b, 1); + if (b > -1) { + if (ssLen >= 200 && 100 > ssLen) { + secondInContext.splice(b, 1); + } + } else { + secondInContext.push([a, sourceLine]); } - } else { - secondInContext.push([a, sourceLine]); } - } - }()); - (function diffview__opcodes_diffArray_algorithm() { - var a = 0, - matchingFirst = 0, - matchingSecond = 0, - matchingSize = 0, - tag = "", - firstSize = 0, - secondSize = 0, - blocks = get_matching_blocks(), - blockLength = blocks.length, - closerMatch = function diffview__opcodes_diffArray_algorithm_closerMatch(current, next, compare) { - var diffspot = function diffview__opcodes_diffArray_algorithm_closerMatch_diffspot(test, base) { - var b = 0, - cleanedTest = test - .replace(/^(\s+)/, "") - .split(""), - minSize = Math.min(cleanedTest.length, base.length); - for (b = 0; b < minSize; b += 1) { - if (cleanedTest[b] !== base[b]) { - return b; + }()); + (function diffview__opcodes_diffArray_algorithm() { + var a = 0, + matchingFirst = 0, + matchingSecond = 0, + matchingSize = 0, + tag = "", + firstSize = 0, + secondSize = 0, + blocks = get_matching_blocks(), + blockLength = blocks.length, + closerMatch = function diffview__opcodes_diffArray_algorithm_closerMatch(current, next, compare) { + var diffspot = function diffview__opcodes_diffArray_algorithm_closerMatch_diffspot(test, base) { + var b = 0, + cleanedTest = test + .replace(/^(\s+)/, "") + .split(""), + minSize = Math.min(cleanedTest.length, base.length); + for (b = 0; b < minSize; b += 1) { + if (cleanedTest[b] !== base[b]) { + return b; + } + } + return b; + }, + cleanedCompare = compare + .replace(/^(\s+)/, "") + .split(""), + test = diffspot(next, cleanedCompare) - diffspot(current, cleanedCompare); + if (test > 0) { + return true; + } + return false; + }; + for (a = 0; a < blockLength; a += 1) { + matchingFirst = blocks[a][0]; + matchingSecond = blocks[a][1]; + matchingSize = blocks[a][2]; + tag = ""; + if (firstSize < matchingFirst && secondSize < matchingSecond) { + if (firstSize - secondSize !== matchingFirst - matchingSecond && secondSize - matchingSecond < 3 && firstSize - matchingFirst < 3) { + if (reverse === true && firstSize - matchingFirst > secondSize - matchingSecond) { + if (closerMatch(sourceSecond[secondSize], sourceSecond[secondSize + 1], sourceFirst[firstSize]) === true) { + answer.push([ + "delete", secondSize, secondSize + 1, + firstSize, + firstSize + ]); + answer.push([ + "replace", secondSize + 1, + matchingSecond, + firstSize, + matchingFirst + ]); + } else { + answer.push(["replace", secondSize, matchingSecond, firstSize, matchingFirst]); + } + } else if (reverse === false && matchingSecond - secondSize > matchingFirst - firstSize) { + if (closerMatch(sourceSecond[secondSize], sourceSecond[secondSize + 1], sourceFirst[firstSize]) === true) { + answer.push([ + "insert", firstSize, firstSize, secondSize, secondSize + 1 + ]); + answer.push([ + "replace", firstSize, matchingFirst, secondSize + 1, + matchingSecond + ]); + } else { + answer.push(["replace", firstSize, matchingFirst, secondSize, matchingSecond]); } - } - return b; - }, - cleanedCompare = compare - .replace(/^(\s+)/, "") - .split(""), - test = diffspot(next, cleanedCompare) - diffspot(current, cleanedCompare); - if (test > 0) { - return true; - } - return false; - }; - for (a = 0; a < blockLength; a += 1) { - matchingFirst = blocks[a][0]; - matchingSecond = blocks[a][1]; - matchingSize = blocks[a][2]; - tag = ""; - if (firstSize < matchingFirst && secondSize < matchingSecond) { - if (firstSize - secondSize !== matchingFirst - matchingSecond && secondSize - matchingSecond < 3 && firstSize - matchingFirst < 3) { - if (reverse === true && firstSize - matchingFirst > secondSize - matchingSecond) { - if (closerMatch(sourceSecond[secondSize], sourceSecond[secondSize + 1], sourceFirst[firstSize]) === true) { - answer.push([ - "delete", secondSize, secondSize + 1, - firstSize, - firstSize - ]); - answer.push([ - "replace", secondSize + 1, - matchingSecond, - firstSize, - matchingFirst - ]); - } else { - answer.push(["replace", secondSize, matchingSecond, firstSize, matchingFirst]); - } - } else if (reverse === false && matchingSecond - secondSize > matchingFirst - firstSize) { - if (closerMatch(sourceSecond[secondSize], sourceSecond[secondSize + 1], sourceFirst[firstSize]) === true) { - answer.push([ - "insert", firstSize, firstSize, secondSize, secondSize + 1 - ]); - answer.push([ - "replace", firstSize, matchingFirst, secondSize + 1, - matchingSecond - ]); } else { - answer.push(["replace", firstSize, matchingFirst, secondSize, matchingSecond]); + tag = "replace"; } } else { tag = "replace"; } - } else { - tag = "replace"; + } else if (firstSize < matchingFirst) { + if (reverse === true) { + tag = "insert"; + } else { + tag = "delete"; + } + } else if (secondSize < matchingSecond) { + if (reverse === true) { + tag = "delete"; + } else { + tag = "insert"; + } } - } else if (firstSize < matchingFirst) { - if (reverse === true) { - tag = "insert"; - } else { - tag = "delete"; + if (tag !== "") { + if (reverse === true) { + answer.push([tag, secondSize, matchingSecond, firstSize, matchingFirst]); + } else { + answer.push([tag, firstSize, matchingFirst, secondSize, matchingSecond]); + } } - } else if (secondSize < matchingSecond) { - if (reverse === true) { - tag = "delete"; - } else { - tag = "insert"; + firstSize = matchingFirst + matchingSize; + secondSize = matchingSecond + matchingSize; + if (matchingSize > 0) { + if (reverse === true) { + answer.push(["equal", matchingSecond, secondSize, matchingFirst, firstSize]); + } else { + answer.push(["equal", matchingFirst, firstSize, matchingSecond, secondSize]); + } } } - if (tag !== "") { - if (reverse === true) { - answer.push([tag, secondSize, matchingSecond, firstSize, matchingFirst]); - } else { - answer.push([tag, firstSize, matchingFirst, secondSize, matchingSecond]); + }()); + }()); + return answer; + }()); + //after the opcodes generate the other two core pieces of logic + //are quaranteened into an anonymous function. + return (function diffview__report() { + var a = 0, + i = 0, + node = ["
"], + data = (options.diffcli === true) + ? [ + [], + [], + [], + [], + [], + [] + ] + : [ + [], [], [], [] + ], + baseStart = 0, + baseEnd = 0, + newStart = 0, + newEnd = 0, + rowcnt = 0, + rowItem = -1, + rcount = 0, + foldcount = 0, + foldstart = -1, + jump = 0, + finaldoc = "", + tabFix = (tab === "") + ? "" + : new RegExp("^((" + tab.replace(/\\/g, "\\") + ")+)"), + noTab = function diffview__report_noTab(str) { + var b = 0, + strLen = str.length, + output = []; + for (b = 0; b < strLen; b += 1) { + output.push(str[b].replace(tabFix, "")); + } + return output; + }, + baseTab = (tab === "") + ? [] + : noTab(baseTextArray), + newTab = (tab === "") + ? [] + : noTab(newTextArray), + opcodesLength = opcodes.length, + change = "", + btest = false, + ntest = false, + repeat = false, + ctest = true, + code = [], + charcompOutput = [], + //this is the character comparison logic that performs + //the 'largest common subsequence' between two lines of + //code + charcomp = function diffview__report_charcomp(lineA, lineB) { + var b = 0, + dataA = [], + dataB = [], + cleanedA = (options.diffcli === true) + ? lineA + : lineA + .replace(/ /g, " ") + .replace(/ /g, " ") + .replace(/</g, "<") + .replace(/>/g, ">") + .replace(/\$#lt;/g, "<") + .replace(/\$#gt;/g, ">") + .replace(/&/g, "&"), + cleanedB = (options.diffcli === true) + ? lineB + : lineB + .replace(/ /g, " ") + .replace(/ /g, " ") + .replace(/</g, "<") + .replace(/>/g, ">") + .replace(/\$#lt;/g, "<") + .replace(/\$#gt;/g, ">") + .replace(/&/g, "&"), + dataMinLength = 0, + currentdiff = [], + regStart = (/_pdiffdiff\u005f/g), + regEnd = (/_epdiffdiff\u005f/g), + strStart = "_pdiffdiff\u005f", + strEnd = "_epdiffdiff\u005f", + tabdiff = (function diffview__report_charcomp_tabdiff() { + var tabMatchA = "", + tabMatchB = "", + splitA = "", + splitB = "", + analysis = [], + matchListA = cleanedA.match(tabFix), + matchListB = cleanedB.match(tabFix); + if (matchListA === null || matchListB === null || (matchListA[0] === "" && matchListA.length === 1) || (matchListB[0] === "" && matchListB.length === 1)) { + return ["", "", cleanedA, cleanedB]; } - } - firstSize = matchingFirst + matchingSize; - secondSize = matchingSecond + matchingSize; - if (matchingSize > 0) { - if (reverse === true) { - answer.push(["equal", matchingSecond, secondSize, matchingFirst, firstSize]); + tabMatchA = matchListA[0]; + tabMatchB = matchListB[0]; + splitA = cleanedA.split(tabMatchA)[1]; + splitB = cleanedB.split(tabMatchB)[1]; + if (tabMatchA.length > tabMatchB.length) { + analysis = tabMatchA.split(tabMatchB); + tabMatchA = tabMatchB + strStart + analysis[1] + strEnd; + tabMatchB = tabMatchB + strStart + strEnd; } else { - answer.push(["equal", matchingFirst, firstSize, matchingSecond, secondSize]); + analysis = tabMatchB.split(tabMatchA); + tabMatchB = tabMatchA + strStart + analysis[1] + strEnd; + tabMatchA = tabMatchA + strStart + strEnd; } - } - } - }()); - }()); - return answer; - }()); - //after the opcodes generate the other two core pieces of logic - //are quaranteened into an anonymous function. - return (function diffview__report() { - var a = 0, - i = 0, - node = ["
"], - data = (options.diffcli === true) - ? [ - [], - [], - [], - [], - [], - [] - ] - : [ - [], [], [], [] - ], - baseStart = 0, - baseEnd = 0, - newStart = 0, - newEnd = 0, - rowcnt = 0, - rowItem = -1, - rcount = 0, - foldcount = 0, - foldstart = -1, - jump = 0, - finaldoc = "", - tabFix = (tab === "") - ? "" - : new RegExp("^((" + tab.replace(/\\/g, "\\") + ")+)"), - noTab = function diffview__report_noTab(str) { - var b = 0, - strLen = str.length, - output = []; - for (b = 0; b < strLen; b += 1) { - output.push(str[b].replace(tabFix, "")); - } - return output; - }, - baseTab = (tab === "") - ? [] - : noTab(baseTextArray), - newTab = (tab === "") - ? [] - : noTab(newTextArray), - opcodesLength = opcodes.length, - change = "", - btest = false, - ntest = false, - repeat = false, - ctest = true, - code = [], - charcompOutput = [], - //this is the character comparison logic that performs - //the 'largest common subsequence' between two lines of - //code - charcomp = function diffview__report_charcomp(lineA, lineB) { - var b = 0, - dataA = [], - dataB = [], - cleanedA = (options.diffcli === true) - ? lineA - : lineA - .replace(/ /g, " ") - .replace(/ /g, " ") - .replace(/</g, "<") - .replace(/>/g, ">") - .replace(/\$#lt;/g, "<") - .replace(/\$#gt;/g, ">") - .replace(/&/g, "&"), - cleanedB = (options.diffcli === true) - ? lineB - : lineB - .replace(/ /g, " ") - .replace(/ /g, " ") - .replace(/</g, "<") - .replace(/>/g, ">") - .replace(/\$#lt;/g, "<") - .replace(/\$#gt;/g, ">") - .replace(/&/g, "&"), - dataMinLength = 0, - currentdiff = [], - regStart = (/_pdiffdiff\u005f/g), - regEnd = (/_epdiffdiff\u005f/g), - strStart = "_pdiffdiff\u005f", - strEnd = "_epdiffdiff\u005f", - tabdiff = (function diffview__report_charcomp_tabdiff() { - var tabMatchA = "", - tabMatchB = "", - splitA = "", - splitB = "", - analysis = [], - matchListA = cleanedA.match(tabFix), - matchListB = cleanedB.match(tabFix); - if (matchListA === null || matchListB === null || (matchListA[0] === "" && matchListA.length === 1) || (matchListB[0] === "" && matchListB.length === 1)) { - return ["", "", cleanedA, cleanedB]; - } - tabMatchA = matchListA[0]; - tabMatchB = matchListB[0]; - splitA = cleanedA.split(tabMatchA)[1]; - splitB = cleanedB.split(tabMatchB)[1]; - if (tabMatchA.length > tabMatchB.length) { - analysis = tabMatchA.split(tabMatchB); - tabMatchA = tabMatchB + strStart + analysis[1] + strEnd; - tabMatchB = tabMatchB + strStart + strEnd; - } else { - analysis = tabMatchB.split(tabMatchA); - tabMatchB = tabMatchA + strStart + analysis[1] + strEnd; - tabMatchA = tabMatchA + strStart + strEnd; - } - return [tabMatchA, tabMatchB, splitA, splitB]; - }()), - //compare is the fuzzy string comparison algorithm - compare = function diffview__report_charcomp_compare(start) { - var x = 0, - y = 0, - max = Math.max(dataA.length, dataB.length), - store = [], - sorta = function diffview__report_charcomp_compare_sorta(a, b) { - if (a[1] - a[0] < b[1] - b[0]) { - return 1; - } - return -1; - }, - sortb = function diffview__report_charcomp_compare_sortb(a, b) { - if (a[0] + a[1] > b[0] + b[1]) { - return 1; - } - return -1; - }, - whitetest = (/^(\s+)$/), - whitespace = false, - wordtest = false; - //first gather a list of all matching indexes into an array - for (x = start; x < dataMinLength; x += 1) { - for (y = start; y < max; y += 1) { - if (dataA[x] === dataB[y] || dataB[x] === dataA[y]) { - store.push([x, y]); - if (dataA[y] === dataB[x] && dataA[y + 1] === dataB[x + 1] && whitetest.test(dataB[x - 1]) === true) { - wordtest = true; - store = [[x, y]]; + return [tabMatchA, tabMatchB, splitA, splitB]; + }()), + //compare is the fuzzy string comparison algorithm + compare = function diffview__report_charcomp_compare(start) { + var x = 0, + y = 0, + max = Math.max(dataA.length, dataB.length), + store = [], + sorta = function diffview__report_charcomp_compare_sorta(a, b) { + if (a[1] - a[0] < b[1] - b[0]) { + return 1; } - if (dataA[x] === dataB[y] && dataA[x + 1] === dataB[y + 1] && whitetest.test(dataB[y - 1]) === true) { - wordtest = true; - store = [[x, y]]; + return -1; + }, + sortb = function diffview__report_charcomp_compare_sortb(a, b) { + if (a[0] + a[1] > b[0] + b[1]) { + return 1; + } + return -1; + }, + whitetest = (/^(\s+)$/), + whitespace = false, + wordtest = false; + //first gather a list of all matching indexes into an array + for (x = start; x < dataMinLength; x += 1) { + for (y = start; y < max; y += 1) { + if (dataA[x] === dataB[y] || dataB[x] === dataA[y]) { + store.push([x, y]); + if (dataA[y] === dataB[x] && dataA[y + 1] === dataB[x + 1] && whitetest.test(dataB[x - 1]) === true) { + wordtest = true; + store = [[x, y]]; + } + if (dataA[x] === dataB[y] && dataA[x + 1] === dataB[y + 1] && whitetest.test(dataB[y - 1]) === true) { + wordtest = true; + store = [[x, y]]; + } + break; } + } + if (wordtest === true) { break; } } - if (wordtest === true) { - break; + //if there are no character matches then quit out + if (store.length === 0) { + return [dataMinLength, max, 0, whitespace]; } - } - //if there are no character matches then quit out - if (store.length === 0) { - return [dataMinLength, max, 0, whitespace]; - } - //take the list of matches and sort it - //first sort by size of change with shortest up front - //second sort by sum of change start and end - //the second sort results in the smallest change from the earliest point - store.sort(sorta); - if (dataMinLength - start < 5000) { - store.sort(sortb); - } - //x should always be the shorter index (change start) - if (store[0][0] < store[0][1]) { - x = store[0][0]; - y = store[0][1]; - } else { - y = store[0][0]; - x = store[0][1]; - } - if (options.diffspaceignore === true) { - if (whitetest.test(dataA.join("").slice(b, x)) === true || whitetest.test(dataB.join("").slice(b, x)) === true) { - whitespace = true; + //take the list of matches and sort it + //first sort by size of change with shortest up front + //second sort by sum of change start and end + //the second sort results in the smallest change from the earliest point + store.sort(sorta); + if (dataMinLength - start < 5000) { + store.sort(sortb); } - } - //package the output - if (dataA[y] === dataB[x]) { - if (dataA[y - 1] === dataB[x - 1] && x !== start) { - x -= 1; - y -= 1; + //x should always be the shorter index (change start) + if (store[0][0] < store[0][1]) { + x = store[0][0]; + y = store[0][1]; + } else { + y = store[0][0]; + x = store[0][1]; } - return [x, y, 0, whitespace]; - } - if (dataA[x] === dataB[y]) { - if (dataA[x - 1] === dataB[y - 1] && x !== start) { - x -= 1; - y -= 1; + if (options.diffspaceignore === true) { + if (whitetest.test(dataA.join("").slice(b, x)) === true || whitetest.test(dataB.join("").slice(b, x)) === true) { + whitespace = true; + } + } + //package the output + if (dataA[y] === dataB[x]) { + if (dataA[y - 1] === dataB[x - 1] && x !== start) { + x -= 1; + y -= 1; + } + return [x, y, 0, whitespace]; } - return [x, y, 1, whitespace]; + if (dataA[x] === dataB[y]) { + if (dataA[x - 1] === dataB[y - 1] && x !== start) { + x -= 1; + y -= 1; + } + return [x, y, 1, whitespace]; + } + }; + //if same after accounting for character entities then exit + if (cleanedA === cleanedB) { + return [lineA, lineB]; + } + //prevent extra error counting that occurred before entering this function + errorout -= 1; + //diff for tabs + if (tabFix !== "" && cleanedA.length !== cleanedB.length && cleanedA.replace(tabFix, "") === cleanedB.replace(tabFix, "") && options.diffspaceignore === false) { + errorout += 1; + if (options.diffcli === true) { + tabdiff[0] = tabdiff[0] + tabdiff[2]; + tabdiff[0] = tabdiff[0] + .replace(regStart, "") + .replace(regEnd, ""); + tabdiff[1] = tabdiff[1] + tabdiff[3]; + tabdiff[1] = tabdiff[1] + .replace(regStart, "") + .replace(regEnd, ""); + return [tabdiff[0], tabdiff[1]]; } - }; - //if same after accounting for character entities then exit - if (cleanedA === cleanedB) { - return [lineA, lineB]; - } - //prevent extra error counting that occurred before entering this function - errorout -= 1; - //diff for tabs - if (tabFix !== "" && cleanedA.length !== cleanedB.length && cleanedA.replace(tabFix, "") === cleanedB.replace(tabFix, "") && options.diffspaceignore === false) { - errorout += 1; - if (options.diffcli === true) { tabdiff[0] = tabdiff[0] + tabdiff[2]; tabdiff[0] = tabdiff[0] - .replace(regStart, "") - .replace(regEnd, ""); + .replace(/&/g, "&") + .replace(//g, ">") + .replace(regStart, "") + .replace(regEnd, ""); tabdiff[1] = tabdiff[1] + tabdiff[3]; tabdiff[1] = tabdiff[1] - .replace(regStart, "") - .replace(regEnd, ""); + .replace(/&/g, "&") + .replace(//g, ">") + .replace(regStart, "") + .replace(regEnd, ""); return [tabdiff[0], tabdiff[1]]; } - tabdiff[0] = tabdiff[0] + tabdiff[2]; - tabdiff[0] = tabdiff[0] - .replace(/&/g, "&") - .replace(//g, ">") - .replace(regStart, "") - .replace(regEnd, ""); - tabdiff[1] = tabdiff[1] + tabdiff[3]; - tabdiff[1] = tabdiff[1] - .replace(/&/g, "&") - .replace(//g, ">") - .replace(regStart, "") - .replace(regEnd, ""); - return [tabdiff[0], tabdiff[1]]; - } - //turn the pruned input into arrays - dataA = cleanedA.split(""); - dataB = cleanedB.split(""); - //the length of the shortest array - dataMinLength = Math.min(dataA.length, dataB.length); - for (b = 0; b < dataMinLength; b += 1) { - //if undefined break the loop - if (dataA[b] === undefined || dataB[b] === undefined) { - break; - } - //iterate until the arrays are not the same - if (dataA[b] !== dataB[b]) { - //fuzzy string comparison returns an array with these indexes - //0 - shorter ending index of difference - //1 - longer ending index of difference - //2 - 0 if index 2 is for dataA or 1 for dataB - //3 - whether the difference is only whitespace - currentdiff = compare(b); - //supply the difference start indicator - if (currentdiff[3] === false) { - //count each difference - errorout += 1; - if (b > 0) { - dataA[b - 1] = dataA[b - 1] + strStart; - dataB[b - 1] = dataB[b - 1] + strStart; - } else { - dataA[b] = strStart + dataA[b]; - dataB[b] = strStart + dataB[b]; - } - //complex decision tree on how to supply difference end indicator - if (currentdiff[2] === 1) { - if (currentdiff[0] === 0) { - dataA[0] = dataA[0].replace(regStart, strStart + strEnd); - } else if (currentdiff[0] === dataMinLength) { - if (dataB.length === dataMinLength) { - dataA[dataA.length - 1] = dataA[dataA.length - 1] + strEnd; + //turn the pruned input into arrays + dataA = cleanedA.split(""); + dataB = cleanedB.split(""); + //the length of the shortest array + dataMinLength = Math.min(dataA.length, dataB.length); + for (b = 0; b < dataMinLength; b += 1) { + //if undefined break the loop + if (dataA[b] === undefined || dataB[b] === undefined) { + break; + } + //iterate until the arrays are not the same + if (dataA[b] !== dataB[b]) { + //fuzzy string comparison returns an array with these indexes + //0 - shorter ending index of difference + //1 - longer ending index of difference + //2 - 0 if index 2 is for dataA or 1 for dataB + //3 - whether the difference is only whitespace + currentdiff = compare(b); + //supply the difference start indicator + if (currentdiff[3] === false) { + //count each difference + errorout += 1; + if (b > 0) { + dataA[b - 1] = dataA[b - 1] + strStart; + dataB[b - 1] = dataB[b - 1] + strStart; + } else { + dataA[b] = strStart + dataA[b]; + dataB[b] = strStart + dataB[b]; + } + //complex decision tree on how to supply difference end indicator + if (currentdiff[2] === 1) { + if (currentdiff[0] === 0) { + dataA[0] = dataA[0].replace(regStart, strStart + strEnd); + } else if (currentdiff[0] === dataMinLength) { + if (dataB.length === dataMinLength) { + dataA[dataA.length - 1] = dataA[dataA.length - 1] + strEnd; + } else { + dataA[currentdiff[0] - 1] = dataA[currentdiff[0] - 1] + strEnd; + } } else { - dataA[currentdiff[0] - 1] = dataA[currentdiff[0] - 1] + strEnd; + if (dataA[currentdiff[0]].indexOf(strStart) > -1) { + dataA[currentdiff[0]] = dataA[currentdiff[0]] + strEnd; + } else if (currentdiff[1] - currentdiff[0] === currentdiff[0]) { + dataA[b] = strEnd + dataA[b]; + } else { + dataA[currentdiff[0]] = strEnd + dataA[currentdiff[0]]; + } } - } else { - if (dataA[currentdiff[0]].indexOf(strStart) > -1) { - dataA[currentdiff[0]] = dataA[currentdiff[0]] + strEnd; + if (currentdiff[1] > dataB.length - 1 || currentdiff[0] === dataMinLength) { + dataB[dataB.length - 1] = dataB[dataB.length - 1] + strEnd; } else if (currentdiff[1] - currentdiff[0] === currentdiff[0]) { - dataA[b] = strEnd + dataA[b]; + dataB[b + (currentdiff[1] - currentdiff[0])] = strEnd + dataB[b + (currentdiff[1] - currentdiff[0])]; } else { - dataA[currentdiff[0]] = strEnd + dataA[currentdiff[0]]; + dataB[currentdiff[1]] = strEnd + dataB[currentdiff[1]]; } - } - if (currentdiff[1] > dataB.length - 1 || currentdiff[0] === dataMinLength) { - dataB[dataB.length - 1] = dataB[dataB.length - 1] + strEnd; - } else if (currentdiff[1] - currentdiff[0] === currentdiff[0]) { - dataB[b + (currentdiff[1] - currentdiff[0])] = strEnd + dataB[b + (currentdiff[1] - currentdiff[0])]; } else { - dataB[currentdiff[1]] = strEnd + dataB[currentdiff[1]]; - } - } else { - if (currentdiff[0] === 0) { - dataB[0] = dataB[0].replace(regStart, strStart + strEnd); - } else if (currentdiff[0] === dataMinLength) { - if (dataA.length === dataMinLength) { - dataB[dataB.length - 1] = dataB[dataB.length - 1] + strEnd; + if (currentdiff[0] === 0) { + dataB[0] = dataB[0].replace(regStart, strStart + strEnd); + } else if (currentdiff[0] === dataMinLength) { + if (dataA.length === dataMinLength) { + dataB[dataB.length - 1] = dataB[dataB.length - 1] + strEnd; + } else { + dataB[currentdiff[0] - 1] = dataB[currentdiff[0] - 1] + strEnd; + } } else { - dataB[currentdiff[0] - 1] = dataB[currentdiff[0] - 1] + strEnd; + if (dataB[currentdiff[0]].indexOf(strStart) > -1) { + dataB[currentdiff[0]] = dataB[currentdiff[0]] + strEnd; + } else if (currentdiff[0] - currentdiff[1] === currentdiff[1]) { + dataB[b] = strEnd + dataB[b]; + } else { + dataB[currentdiff[0]] = strEnd + dataB[currentdiff[0]]; + } } - } else { - if (dataB[currentdiff[0]].indexOf(strStart) > -1) { - dataB[currentdiff[0]] = dataB[currentdiff[0]] + strEnd; + if (currentdiff[1] > dataA.length - 1 || currentdiff[0] === dataMinLength) { + dataA[dataA.length - 1] = dataA[dataA.length - 1] + strEnd; } else if (currentdiff[0] - currentdiff[1] === currentdiff[1]) { - dataB[b] = strEnd + dataB[b]; + dataA[b + (currentdiff[0] - currentdiff[1])] = strEnd + dataA[b + (currentdiff[0] - currentdiff[1])]; } else { - dataB[currentdiff[0]] = strEnd + dataB[currentdiff[0]]; + dataA[currentdiff[1]] = strEnd + dataA[currentdiff[1]]; } } - if (currentdiff[1] > dataA.length - 1 || currentdiff[0] === dataMinLength) { - dataA[dataA.length - 1] = dataA[dataA.length - 1] + strEnd; - } else if (currentdiff[0] - currentdiff[1] === currentdiff[1]) { - dataA[b + (currentdiff[0] - currentdiff[1])] = strEnd + dataA[b + (currentdiff[0] - currentdiff[1])]; + } + //we must rebase the array with the shorter difference + //so that the end of the current difference is on the + //same index. This provides a common baseline by which + //to find the next unmatching index + if (currentdiff[1] > currentdiff[0] && currentdiff[1] - currentdiff[0] < 1000) { + if (currentdiff[2] === 1) { + do { + dataA.unshift(""); + currentdiff[0] += 1; + } while (currentdiff[1] > currentdiff[0]); } else { - dataA[currentdiff[1]] = strEnd + dataA[currentdiff[1]]; + do { + dataB.unshift(""); + currentdiff[0] += 1; + } while (currentdiff[1] > currentdiff[0]); } } + //since the previous logic will grow the shorter array + //we have to redefine the shortest length + dataMinLength = Math.min(dataA.length, dataB.length); + //assign the incrementer to the end of the longer difference + b = currentdiff[1]; } - //we must rebase the array with the shorter difference - //so that the end of the current difference is on the - //same index. This provides a common baseline by which - //to find the next unmatching index - if (currentdiff[1] > currentdiff[0] && currentdiff[1] - currentdiff[0] < 1000) { - if (currentdiff[2] === 1) { - do { - dataA.unshift(""); - currentdiff[0] += 1; - } while (currentdiff[1] > currentdiff[0]); - } else { - do { - dataB.unshift(""); - currentdiff[0] += 1; - } while (currentdiff[1] > currentdiff[0]); - } - } - //since the previous logic will grow the shorter array - //we have to redefine the shortest length - dataMinLength = Math.min(dataA.length, dataB.length); - //assign the incrementer to the end of the longer difference - b = currentdiff[1]; } - } - //if one array is longer than the other and not identified as different - //then identify this difference in length - if (dataA.length > dataB.length && dataB[dataB.length - 1] !== undefined && dataB[dataB.length - 1].indexOf(strEnd) < 1) { - dataB.push(strStart + strEnd); - dataA[dataB.length - 1] = strStart + dataA[dataB.length - 1]; - dataA[dataA.length - 1] = dataA[dataA.length - 1] + strEnd; - errorout += 1; - } - if (dataB.length > dataA.length && dataA[dataA.length - 1] !== undefined && dataA[dataA.length - 1].indexOf(strEnd) < 1) { - dataA.push(strStart + strEnd); - dataB[dataA.length - 1] = strStart + dataB[dataA.length - 1]; - dataB[dataB.length - 1] = dataB[dataB.length - 1] + strEnd; - errorout += 1; - } - //options.diffcli output doesn't need XML protected characters - //to be escaped because its output is the command line - if (options.diffcli === true) { + //if one array is longer than the other and not identified as different + //then identify this difference in length + if (dataA.length > dataB.length && dataB[dataB.length - 1] !== undefined && dataB[dataB.length - 1].indexOf(strEnd) < 1) { + dataB.push(strStart + strEnd); + dataA[dataB.length - 1] = strStart + dataA[dataB.length - 1]; + dataA[dataA.length - 1] = dataA[dataA.length - 1] + strEnd; + errorout += 1; + } + if (dataB.length > dataA.length && dataA[dataA.length - 1] !== undefined && dataA[dataA.length - 1].indexOf(strEnd) < 1) { + dataA.push(strStart + strEnd); + dataB[dataA.length - 1] = strStart + dataB[dataA.length - 1]; + dataB[dataB.length - 1] = dataB[dataB.length - 1] + strEnd; + errorout += 1; + } + //options.diffcli output doesn't need XML protected characters + //to be escaped because its output is the command line + if (options.diffcli === true) { + return [ + dataA + .join("") + .replace(regStart, "") + .replace(regEnd, ""), + dataB + .join("") + .replace(regStart, "") + .replace(regEnd, "") + ]; + } return [ dataA .join("") - .replace(regStart, "") - .replace(regEnd, ""), + .replace(/&/g, "&") + .replace(//g, ">") + .replace(regStart, "") + .replace(regEnd, ""), dataB .join("") - .replace(regStart, "") - .replace(regEnd, "") + .replace(/&/g, "&") + .replace(//g, ">") + .replace(regStart, "") + .replace(regEnd, "") ]; + }; + if (options.diffcli === false) { + if (options.diffview === "inline") { + node.push("

"); + node.push(options.sourcelabel); + node.push(" vs. "); + node.push(options.difflabel); + node.push("

    "); + } else { + data[0].push("

    "); + data[0].push(options.sourcelabel); + data[0].push("

      "); + data[2].push("

      "); + data[2].push(options.difflabel); + data[2].push("

        "); } - return [ - dataA - .join("") - .replace(/&/g, "&") - .replace(//g, ">") - .replace(regStart, "") - .replace(regEnd, ""), - dataB - .join("") - .replace(/&/g, "&") - .replace(//g, ">") - .replace(regStart, "") - .replace(regEnd, "") - ]; - }; - if (options.diffcli === false) { - if (options.diffview === "inline") { - node.push("

        "); - node.push(options.sourcelabel); - node.push(" vs. "); - node.push(options.difflabel); - node.push("

          "); - } else { - data[0].push("

          "); - data[0].push(options.sourcelabel); - data[0].push("

            "); - data[2].push("

            "); - data[2].push(options.difflabel); - data[2].push("

              "); } - } - for (a = 0; a < opcodesLength; a += 1) { - code = opcodes[a]; - change = code[0]; - baseStart = code[1]; - baseEnd = code[2]; - newStart = code[3]; - newEnd = code[4]; - rowcnt = Math.max(baseEnd - baseStart, newEnd - newStart); - ctest = true; - for (i = 0; i < rowcnt; i += 1) { - //apply options.context collapsing for the output, if needed - if (options.context > -1 && opcodes.length > 1 && ((a > 0 && i === options.context) || (a === 0 && i === 0)) && change === "equal") { - ctest = false; - jump = rowcnt - ((a === 0 - ? 1 - : 2) * options.context); - if (jump > 1) { - baseStart += jump; - newStart += jump; - i += jump - 1; - if (options.diffcli === true) { - data[5].push([baseStart, newStart]); - } else { - data[0].push("
            1. ...
            2. "); - if (options.diffview !== "inline") { - data[1].push("
            3. "); + for (a = 0; a < opcodesLength; a += 1) { + code = opcodes[a]; + change = code[0]; + baseStart = code[1]; + baseEnd = code[2]; + newStart = code[3]; + newEnd = code[4]; + rowcnt = Math.max(baseEnd - baseStart, newEnd - newStart); + ctest = true; + for (i = 0; i < rowcnt; i += 1) { + //apply options.context collapsing for the output, if needed + if (options.context > -1 && opcodes.length > 1 && ((a > 0 && i === options.context) || (a === 0 && i === 0)) && change === "equal") { + ctest = false; + jump = rowcnt - ((a === 0 + ? 1 + : 2) * options.context); + if (jump > 1) { + baseStart += jump; + newStart += jump; + i += jump - 1; + if (options.diffcli === true) { + data[5].push([baseStart, newStart]); + } else { + data[0].push("
            4. ...
            5. "); + if (options.diffview !== "inline") { + data[1].push("
            6. "); + } + data[2].push("
            7. ...
            8. "); + data[3].push("
            9. "); + } + if (a + 1 === opcodes.length) { + break; } - data[2].push("
            10. ...
            11. "); - data[3].push("
            12. "); - } - if (a + 1 === opcodes.length) { - break; } + } else if (change !== "equal") { + diffline += 1; } - } else if (change !== "equal") { - diffline += 1; - } - foldcount += 1; - if (baseTextArray[baseStart] !== newTextArray[newStart] && change === "equal") { - change = "replace"; - } - //this is a check against false positives incurred - //by increasing or reducing of nesting. At this - //time it only checks one level deep. - if (tab !== "") { - if (btest === false && baseTextArray[baseEnd] !== newTextArray[newEnd] && typeof baseTextArray[baseStart + 1] === "string" && typeof newTextArray[newStart] === "string" && baseTab[baseStart + 1] === newTab[newStart] && baseTab[baseStart] !== newTab[newStart] && (typeof newTextArray[newStart - 1] !== "string" || baseTab[baseStart] !== newTab[newStart - 1])) { - btest = true; - } else if (ntest === false && baseTextArray[baseEnd] !== newTextArray[newEnd] && typeof newTextArray[newStart + 1] === "string" && typeof baseTextArray[baseStart] === "string" && newTab[newStart + 1] === baseTab[baseStart] && newTab[newStart] !== baseTab[baseStart] && (typeof baseTextArray[baseStart - 1] !== "string" || newTab[newStart] !== baseTab[baseStart - 1])) { - ntest = true; + foldcount += 1; + if (baseTextArray[baseStart] !== newTextArray[newStart] && change === "equal") { + change = "replace"; } - } - if (options.diffcli === true) { - if (options.diffspaceignore === true && change === "replace" && baseTextArray[baseStart] !== undefined && newTextArray[newStart] !== undefined && baseTextArray[baseStart].replace(/\s+/g, "") === newTextArray[newStart].replace(/\s+/g, "")) { - change = "equal"; - errorout -= 1; - } else { + //this is a check against false positives incurred + //by increasing or reducing of nesting. At this + //time it only checks one level deep. + if (tab !== "") { + if (btest === false && baseTextArray[baseEnd] !== newTextArray[newEnd] && typeof baseTextArray[baseStart + 1] === "string" && typeof newTextArray[newStart] === "string" && baseTab[baseStart + 1] === newTab[newStart] && baseTab[baseStart] !== newTab[newStart] && (typeof newTextArray[newStart - 1] !== "string" || baseTab[baseStart] !== newTab[newStart - 1])) { + btest = true; + } else if (ntest === false && baseTextArray[baseEnd] !== newTextArray[newEnd] && typeof newTextArray[newStart + 1] === "string" && typeof baseTextArray[baseStart] === "string" && newTab[newStart + 1] === baseTab[baseStart] && newTab[newStart] !== baseTab[baseStart] && (typeof baseTextArray[baseStart - 1] !== "string" || newTab[newStart] !== baseTab[baseStart - 1])) { + ntest = true; + } + } + if (options.diffcli === true) { + if (options.diffspaceignore === true && change === "replace" && baseTextArray[baseStart] !== undefined && newTextArray[newStart] !== undefined && baseTextArray[baseStart].replace(/\s+/g, "") === newTextArray[newStart].replace(/\s+/g, "")) { + change = "equal"; + errorout -= 1; + } else { + + //data array schema: + //0 - base line number + //1 - base code line + //2 - new line number + //3 - new code line + //4 - change + //5 - index of options.context (not parallel) + if (ntest === true || change === "insert") { + if (options.diffspaceignore === false || (/^(\s+)$/g).test(newTextArray[newStart]) === false) { + data[0].push(0); + data[1].push(""); + data[2].push(newStart + 1); + data[3].push(newTextArray[newStart]); + data[4].push("insert"); + errorout += 1; + } + } else if (btest === true || change === "delete") { + if (options.diffspaceignore === false || (/^(\s+)$/g).test(baseTextArray[baseStart]) === false) { + data[0].push(baseStart + 1); + data[1].push(baseTextArray[baseStart]); + data[2].push(0); + data[3].push(""); + data[4].push("delete"); + errorout += 1; + } + } else if (change === "replace") { + if (baseTextArray[baseStart] !== newTextArray[newStart]) { + if (baseTextArray[baseStart] === "") { + charcompOutput = ["", newTextArray[newStart]]; + } else if (newTextArray[newStart] === "") { + charcompOutput = [baseTextArray[baseStart], ""]; + } else if (baseStart < baseEnd && newStart < newEnd) { + charcompOutput = charcomp(baseTextArray[baseStart], newTextArray[newStart]); + errorout += 1; + } + } + if (baseStart < baseEnd) { + data[0].push(baseStart + 1); + if (newStart < newEnd) { + data[1].push(charcompOutput[0]); + } else { + data[1].push(baseTextArray[baseStart]); + } + data[2].push(0); + data[3].push(""); + data[4].push("delete"); + } + if (newStart < newEnd) { + data[0].push(0); + data[1].push(""); + data[2].push(newStart + 1); + if (baseStart < baseEnd) { + data[3].push(charcompOutput[1]); + } else { + data[3].push(newTextArray[newStart]); + } + data[4].push("insert"); + } + } else if (baseStart < baseEnd || newStart < newEnd) { + if (options.diffspaceignore === false || baseTextArray[baseStart].replace(/\s+/g, "") !== newTextArray[newStart].replace(/\s+/g, "")) { + data[0].push(baseStart + 1); + data[1].push(baseTextArray[baseStart]); + data[2].push(newStart + 1); + data[3].push(newTextArray[newStart]); + data[4].push(change); + if (change !== "equal") { + errorout += 1; + } + } + } + if (btest === true) { + baseStart += 1; + btest = false; + } else if (ntest === true) { + newStart += 1; + ntest = false; + } else { + baseStart += 1; + newStart += 1; + } + } - //data array schema: - //0 - base line number - //1 - base code line - //2 - new line number - //3 - new code line - //4 - change - //5 - index of options.context (not parallel) + //this is the final of the three primary components + //this is where the output is built + } else if (options.diffview === "inline") { + if (options.diffspaceignore === true && change === "replace" && baseTextArray[baseStart].replace(/\s+/g, "") === newTextArray[newStart].replace(/\s+/g, "")) { + change = "equal"; + errorout -= 1; + } + if (options.context < 0 && rowItem < a) { + rowItem = a; + if (foldstart > -1) { + if (data[0][foldstart + 1] === foldcount - 1) { + data[0][foldstart] = "
            13. " + data[0][foldstart].slice(data[0][foldstart].indexOf("line xxx\">- ") + 12); + } else { + data[0][foldstart] = data[0][foldstart].replace("xxx", (foldcount - 1 + rcount)); + } + } + if (change !== "replace") { + data[0].push("
            14. - "); + foldstart = data[0].length - 1; + if (ntest === true || change === "insert") { + data[0].push(" "); + } else { + data[0].push(baseStart + 1); + } + data[0].push("
            15. "); + } else { + rcount += 1; + } + } else if (change !== "replace") { + data[0].push("
            16. "); + if (ntest === true || change === "insert") { + data[0].push(" "); + } else { + data[0].push(baseStart + 1); + } + data[0].push("
            17. "); + } else if (change === "replace") { + rcount += 1; + } if (ntest === true || change === "insert") { - if (options.diffspaceignore === false || (/^(\s+)$/g).test(newTextArray[newStart]) === false) { - data[0].push(0); - data[1].push(""); - data[2].push(newStart + 1); - data[3].push(newTextArray[newStart]); - data[4].push("insert"); - errorout += 1; + data[2].push("
            18. "); + data[2].push(newStart + 1); + data[2].push("
            19. "); + if (options.diffspaceignore === true && newTextArray[newStart].replace(/\s+/g, "") === "") { + data[3].push("
            20. "); + diffline -= 1; + } else { + data[3].push("
            21. "); } + data[3].push(newTextArray[newStart]); + data[3].push("
            22. "); } else if (btest === true || change === "delete") { - if (options.diffspaceignore === false || (/^(\s+)$/g).test(baseTextArray[baseStart]) === false) { - data[0].push(baseStart + 1); - data[1].push(baseTextArray[baseStart]); - data[2].push(0); - data[3].push(""); - data[4].push("delete"); - errorout += 1; + data[2].push("
            23. "); + if (options.diffspaceignore === true && baseTextArray[baseStart].replace(/\s+/g, "") === "") { + data[3].push("
            24. "); + diffline -= 1; + } else { + data[3].push("
            25. "); } + data[3].push(baseTextArray[baseStart]); + data[3].push("
            26. "); } else if (change === "replace") { if (baseTextArray[baseStart] !== newTextArray[newStart]) { if (baseTextArray[baseStart] === "") { @@ -899,42 +1018,51 @@ global.prettydiff.diffview = function diffview_(options) { charcompOutput = [baseTextArray[baseStart], ""]; } else if (baseStart < baseEnd && newStart < newEnd) { charcompOutput = charcomp(baseTextArray[baseStart], newTextArray[newStart]); - errorout += 1; } } if (baseStart < baseEnd) { - data[0].push(baseStart + 1); + data[0].push("
            27. "+ (baseStart + 1) + "
            28. "); + data[2].push("
            29. "); + if (options.diffspaceignore === true && baseTextArray[baseStart].replace(/\s+/g, "") === "") { + data[3].push("
            30. "); + diffline -= 1; + } else { + data[3].push("
            31. "); + } if (newStart < newEnd) { - data[1].push(charcompOutput[0]); + data[3].push(charcompOutput[0]); } else { - data[1].push(baseTextArray[baseStart]); + data[3].push(baseTextArray[baseStart]); } - data[2].push(0); - data[3].push(""); - data[4].push("delete"); + data[3].push("
            32. "); } if (newStart < newEnd) { - data[0].push(0); - data[1].push(""); + data[0].push("
            33. "); + data[2].push("
            34. "); data[2].push(newStart + 1); + data[2].push("
            35. "); + if (options.diffspaceignore === true && newTextArray[newStart].replace(/\s+/g, "") === "") { + data[3].push("
            36. "); + diffline -= 1; + } else { + data[3].push("
            37. "); + } if (baseStart < baseEnd) { data[3].push(charcompOutput[1]); } else { data[3].push(newTextArray[newStart]); } - data[4].push("insert"); + data[3].push("
            38. "); } } else if (baseStart < baseEnd || newStart < newEnd) { - if (options.diffspaceignore === false || baseTextArray[baseStart].replace(/\s+/g, "") !== newTextArray[newStart].replace(/\s+/g, "")) { - data[0].push(baseStart + 1); - data[1].push(baseTextArray[baseStart]); - data[2].push(newStart + 1); - data[3].push(newTextArray[newStart]); - data[4].push(change); - if (change !== "equal") { - errorout += 1; - } - } + data[2].push("
            39. "); + data[2].push(newStart + 1); + data[2].push("
            40. "); + data[3].push("
            41. "); + data[3].push(baseTextArray[baseStart]); + data[3].push("
            42. "); } if (btest === true) { baseStart += 1; @@ -946,308 +1074,183 @@ global.prettydiff.diffview = function diffview_(options) { baseStart += 1; newStart += 1; } - } - - //this is the final of the three primary components - //this is where the output is built - } else if (options.diffview === "inline") { - if (options.diffspaceignore === true && change === "replace" && baseTextArray[baseStart].replace(/\s+/g, "") === newTextArray[newStart].replace(/\s+/g, "")) { - change = "equal"; - errorout -= 1; - } - if (options.context < 0 && rowItem < a) { - rowItem = a; - if (foldstart > -1) { - if (data[0][foldstart + 1] === foldcount - 1) { - data[0][foldstart] = "
            43. " + data[0][foldstart].slice(data[0][foldstart].indexOf("line xxx\">- ") + 12); - } else { - data[0][foldstart] = data[0][foldstart].replace("xxx", (foldcount - 1 + rcount)); - } - } - if (change !== "replace") { - data[0].push("
            44. - "); - foldstart = data[0].length - 1; - if (ntest === true || change === "insert") { - data[0].push(" "); - } else { - data[0].push(baseStart + 1); - } - data[0].push("
            45. "); - } else { - rcount += 1; - } - } else if (change !== "replace") { - data[0].push("
            46. "); - if (ntest === true || change === "insert") { - data[0].push(" "); - } else { - data[0].push(baseStart + 1); - } - data[0].push("
            47. "); - } else if (change === "replace") { - rcount += 1; - } - if (ntest === true || change === "insert") { - data[2].push("
            48. "); - data[2].push(newStart + 1); - data[2].push("
            49. "); - if (options.diffspaceignore === true && newTextArray[newStart].replace(/\s+/g, "") === "") { - data[3].push("
            50. "); - diffline -= 1; - } else { - data[3].push("
            51. "); - } - data[3].push(newTextArray[newStart]); - data[3].push("
            52. "); - } else if (btest === true || change === "delete") { - data[2].push("
            53. "); - if (options.diffspaceignore === true && baseTextArray[baseStart].replace(/\s+/g, "") === "") { - data[3].push("
            54. "); - diffline -= 1; - } else { - data[3].push("
            55. "); - } - data[3].push(baseTextArray[baseStart]); - data[3].push("
            56. "); - } else if (change === "replace") { - if (baseTextArray[baseStart] !== newTextArray[newStart]) { - if (baseTextArray[baseStart] === "") { - charcompOutput = ["", newTextArray[newStart]]; - } else if (newTextArray[newStart] === "") { - charcompOutput = [baseTextArray[baseStart], ""]; - } else if (baseStart < baseEnd && newStart < newEnd) { - charcompOutput = charcomp(baseTextArray[baseStart], newTextArray[newStart]); - } - } - if (baseStart < baseEnd) { - data[0].push("
            57. "+ (baseStart + 1) + "
            58. "); - data[2].push("
            59. "); - if (options.diffspaceignore === true && baseTextArray[baseStart].replace(/\s+/g, "") === "") { - data[3].push("
            60. "); - diffline -= 1; - } else { - data[3].push("
            61. "); - } - if (newStart < newEnd) { - data[3].push(charcompOutput[0]); - } else { - data[3].push(baseTextArray[baseStart]); + } else { + if (btest === false && ntest === false && typeof baseTextArray[baseStart] === "string" && typeof newTextArray[newStart] === "string") { + if (baseTextArray[baseStart] === "" && newTextArray[newStart] !== "") { + change = "insert"; } - data[3].push("
            62. "); - } - if (newStart < newEnd) { - data[0].push("
            63. "); - data[2].push("
            64. "); - data[2].push(newStart + 1); - data[2].push("
            65. "); - if (options.diffspaceignore === true && newTextArray[newStart].replace(/\s+/g, "") === "") { - data[3].push("
            66. "); - diffline -= 1; - } else { - data[3].push("
            67. "); + if (newTextArray[newStart] === "" && baseTextArray[baseStart] !== "") { + change = "delete"; } - if (baseStart < baseEnd) { - data[3].push(charcompOutput[1]); + if (change === "replace" && baseStart < baseEnd && newStart < newEnd && baseTextArray[baseStart] !== newTextArray[newStart]) { + if (options.diffspaceignore === true && baseTextArray[baseStart].replace(/\s+/g, "") === newTextArray[newStart].replace(/\s+/g, "")) { + change = "equal"; + charcompOutput = [baseTextArray[baseStart], newTextArray[newStart]]; + } else { + charcompOutput = charcomp(baseTextArray[baseStart], newTextArray[newStart]); + } } else { - data[3].push(newTextArray[newStart]); - } - data[3].push("
            68. "); - } - } else if (baseStart < baseEnd || newStart < newEnd) { - data[2].push("
            69. "); - data[2].push(newStart + 1); - data[2].push("
            70. "); - data[3].push("
            71. "); - data[3].push(baseTextArray[baseStart]); - data[3].push("
            72. "); - } - if (btest === true) { - baseStart += 1; - btest = false; - } else if (ntest === true) { - newStart += 1; - ntest = false; - } else { - baseStart += 1; - newStart += 1; - } - } else { - if (btest === false && ntest === false && typeof baseTextArray[baseStart] === "string" && typeof newTextArray[newStart] === "string") { - if (baseTextArray[baseStart] === "" && newTextArray[newStart] !== "") { - change = "insert"; - } - if (newTextArray[newStart] === "" && baseTextArray[baseStart] !== "") { - change = "delete"; - } - if (change === "replace" && baseStart < baseEnd && newStart < newEnd && baseTextArray[baseStart] !== newTextArray[newStart]) { - if (options.diffspaceignore === true && baseTextArray[baseStart].replace(/\s+/g, "") === newTextArray[newStart].replace(/\s+/g, "")) { - change = "equal"; charcompOutput = [baseTextArray[baseStart], newTextArray[newStart]]; - } else { - charcompOutput = charcomp(baseTextArray[baseStart], newTextArray[newStart]); } - } else { - charcompOutput = [baseTextArray[baseStart], newTextArray[newStart]]; - } - if (baseStart === Number(data[0][data[0].length - 1].substring(data[0][data[0].length - 1].indexOf(">") + 1, data[0][data[0].length - 1].lastIndexOf("<"))) - 1 || newStart === Number(data[2][data[2].length - 1].substring(data[2][data[2].length - 1].indexOf(">") + 1, data[2][data[2].length - 1].lastIndexOf("<"))) - 1) { - repeat = true; - } - if (repeat === false) { - if (baseStart < baseEnd) { - if (options.context < 0 && rowItem < a) { - rowItem = a; - if (foldstart > -1) { - data[0][foldstart] = data[0][foldstart].replace("xxx", (foldcount - 1)); + if (baseStart === Number(data[0][data[0].length - 1].substring(data[0][data[0].length - 1].indexOf(">") + 1, data[0][data[0].length - 1].lastIndexOf("<"))) - 1 || newStart === Number(data[2][data[2].length - 1].substring(data[2][data[2].length - 1].indexOf(">") + 1, data[2][data[2].length - 1].lastIndexOf("<"))) - 1) { + repeat = true; + } + if (repeat === false) { + if (baseStart < baseEnd) { + if (options.context < 0 && rowItem < a) { + rowItem = a; + if (foldstart > -1) { + data[0][foldstart] = data[0][foldstart].replace("xxx", (foldcount - 1)); + } + data[0].push("
            73. - " + (baseStart + 1) + "
            74. "); + foldstart = data[0].length - 1; + } else { + data[0].push("
            75. " + (baseStart + 1) + "
            76. "); } - data[0].push("
            77. - " + (baseStart + 1) + "
            78. "); - foldstart = data[0].length - 1; - } else { - data[0].push("
            79. " + (baseStart + 1) + "
            80. "); - } - data[1].push("
            81. = newEnd) { - if (options.diffspaceignore === true && baseTextArray[baseStart].replace(/\s+/g, "") === "") { - data[1].push("equal"); - diffline -= 1; + data[1].push("
            82. = newEnd) { + if (options.diffspaceignore === true && baseTextArray[baseStart].replace(/\s+/g, "") === "") { + data[1].push("equal"); + diffline -= 1; + } else { + data[1].push("delete"); + } + } else if (baseTextArray[baseStart] === "" && newTextArray[newStart] !== "") { + data[1].push("empty"); } else { - data[1].push("delete"); + data[1].push(change); } - } else if (baseTextArray[baseStart] === "" && newTextArray[newStart] !== "") { - data[1].push("empty"); - } else { - data[1].push(change); - } - data[1].push("\">"); - data[1].push(charcompOutput[0]); - data[1].push("
            83. "); - } else if (ctest === true) { - if (options.context < 0 && rowItem < a) { - rowItem = a; - if (foldstart > -1) { - data[0][foldstart] = data[0][foldstart].replace("xxx", (foldcount - 1)); + data[1].push("\">"); + data[1].push(charcompOutput[0]); + data[1].push(" "); + } else if (ctest === true) { + if (options.context < 0 && rowItem < a) { + rowItem = a; + if (foldstart > -1) { + data[0][foldstart] = data[0][foldstart].replace("xxx", (foldcount - 1)); + } + data[0].push("
            84. -
            85. "); + foldstart = data[0].length - 1; + } else { + data[0].push("
            86. "); } - data[0].push("
            87. -
            88. "); - foldstart = data[0].length - 1; - } else { - data[0].push("
            89. "); + data[1].push("
            90. "); } - data[1].push("
            91. "); - } - if (newStart < newEnd) { - data[2].push("
            92. " + (newStart + 1) + "
            93. "); - data[3].push("
            94. = baseEnd) { - if (options.diffspaceignore === true && newTextArray[newStart].replace(/\s+/g, "") === "") { - data[3].push("equal"); - diffline -= 1; + if (newStart < newEnd) { + data[2].push("
            95. " + (newStart + 1) + "
            96. "); + data[3].push("
            97. = baseEnd) { + if (options.diffspaceignore === true && newTextArray[newStart].replace(/\s+/g, "") === "") { + data[3].push("equal"); + diffline -= 1; + } else { + data[3].push("insert"); + } + } else if (newTextArray[newStart] === "" && baseTextArray[baseStart] !== "") { + data[3].push("empty"); } else { - data[3].push("insert"); + data[3].push(change); } - } else if (newTextArray[newStart] === "" && baseTextArray[baseStart] !== "") { - data[3].push("empty"); - } else { - data[3].push(change); + data[3].push("\">"); + data[3].push(charcompOutput[1]); + data[3].push("
            98. "); + } else if (ctest === true) { + data[2].push("
            99. "); + data[3].push("
            100. "); } - data[3].push("\">"); - data[3].push(charcompOutput[1]); - data[3].push(" "); - } else if (ctest === true) { + } else { + repeat = false; + } + if (baseStart < baseEnd) { + baseStart += 1; + } + if (newStart < newEnd) { + newStart += 1; + } + } else if (btest === true || (typeof baseTextArray[baseStart] === "string" && typeof newTextArray[newStart] !== "string")) { + if (baseStart !== Number(data[0][data[0].length - 1].substring(data[0][data[0].length - 1].indexOf(">") + 1, data[0][data[0].length - 1].lastIndexOf("<"))) - 1) { + data[0].push("
            101. " + (baseStart + 1) + "
            102. "); + data[1].push("
            103. "); + data[1].push(baseTextArray[baseStart]); + data[1].push("
            104. "); data[2].push("
            105. "); data[3].push("
            106. "); } - } else { - repeat = false; - } - if (baseStart < baseEnd) { + btest = false; baseStart += 1; - } - if (newStart < newEnd) { + } else if (ntest === true || (typeof baseTextArray[baseStart] !== "string" && typeof newTextArray[newStart] === "string")) { + if (newStart !== Number(data[2][data[2].length - 1].substring(data[2][data[2].length - 1].indexOf(">") + 1, data[2][data[2].length - 1].lastIndexOf("<"))) - 1) { + data[0].push("
            107. "); + data[1].push("
            108. "); + data[2].push("
            109. " + (newStart + 1) + "
            110. "); + data[3].push("
            111. "); + data[3].push(newTextArray[newStart]); + data[3].push("
            112. "); + } + ntest = false; newStart += 1; } - } else if (btest === true || (typeof baseTextArray[baseStart] === "string" && typeof newTextArray[newStart] !== "string")) { - if (baseStart !== Number(data[0][data[0].length - 1].substring(data[0][data[0].length - 1].indexOf(">") + 1, data[0][data[0].length - 1].lastIndexOf("<"))) - 1) { - data[0].push("
            113. " + (baseStart + 1) + "
            114. "); - data[1].push("
            115. "); - data[1].push(baseTextArray[baseStart]); - data[1].push("
            116. "); - data[2].push("
            117. "); - data[3].push("
            118. "); - } - btest = false; - baseStart += 1; - } else if (ntest === true || (typeof baseTextArray[baseStart] !== "string" && typeof newTextArray[newStart] === "string")) { - if (newStart !== Number(data[2][data[2].length - 1].substring(data[2][data[2].length - 1].indexOf(">") + 1, data[2][data[2].length - 1].lastIndexOf("<"))) - 1) { - data[0].push("
            119. "); - data[1].push("
            120. "); - data[2].push("
            121. " + (newStart + 1) + "
            122. "); - data[3].push("
            123. "); - data[3].push(newTextArray[newStart]); - data[3].push("
            124. "); - } - ntest = false; - newStart += 1; } } } - } - if (foldstart > -1) { - data[0][foldstart] = data[0][foldstart].replace("xxx", foldcount + rcount); - } - if (options.diffcli === true) { - return [data, errorout, diffline]; - } - node.push(data[0].join("")); - node.push("
              "); - } else { - node.push("\"data\" data-prettydiff-ignore=\"true\">"); - node.push(data[1].join("")); - node.push("
            "); - } - node.push(data[2].join("")); - node.push("
            "); - node.push(data[3].join("")); - if (options.diffview === "inline") { - node.push("
          "); - } else { - node.push("
      "); - } - node.push("

      Diff view written by Pretty D" + - "iff.

    "); - baseTab = (errorout === 1) - ? "" - : "s"; - newTab = (diffline === 1) - ? "" - : "s"; - finaldoc = "

    Number of differences: " + (errorout + diffline) + " difference" + baseTab + " from " + diffline + " line" + newTab + " of code.

    " + node.join(""); - return [finaldoc - .replace(/li\ class=\"equal\"><\/li/g, "li class=\"equal\"> -1) { + data[0][foldstart] = data[0][foldstart].replace("xxx", foldcount + rcount); + } + if (options.diffcli === true) { + return [data, errorout, diffline]; + } + node.push(data[0].join("")); + node.push("
    "); + } else { + node.push("\"data\" data-prettydiff-ignore=\"true\">"); + node.push(data[1].join("")); + node.push("
"); + } + node.push(data[2].join("")); + node.push("
    "); + node.push(data[3].join("")); + if (options.diffview === "inline") { + node.push("
"); + } else { + node.push("
"); + } + node.push("

Diff view written by Pretty D" + + "iff.

"); + baseTab = (errorout === 1) + ? "" + : "s"; + newTab = (diffline === 1) + ? "" + : "s"; + finaldoc = "

Number of differences: " + (errorout + diffline) + " difference" + baseTab + " from " + diffline + " line" + newTab + " of code.

" + node.join(""); + return [finaldoc + .replace(/li\ class=\"equal\"><\/li/g, "li class=\"equal\"> *\/\r\n", - head : "Pretty Diff - The diff" + - "erence tool \r\n", + head : "Pretty Diff - The diff" + + "erence tool