annotate console/lib/vkbeautify.0.97.00.beta.js @ 108:5cb4733c5189

many api changes
author Sonny Piers <sonny@fastmail.net>
date Fri, 13 Jul 2012 15:26:18 +0200
parents lib/vkbeautify.0.97.00.beta.js@c06ec02217ee
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
106
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
1 /**
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
2 * vkBeautify - javascript plugin to pretty-print or minify text in XML, JSON and CSS formats.
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
3 *
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
4 * Version - 0.97.00.beta
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
5 * Copyright (c) 2012 Vadim Kiryukhin
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
6 * vkiryukhin @ gmail.com
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
7 * http://www.eslinstructor.net/vkbeautify/
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
8 *
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
9 * Dual licensed under the MIT and GPL licenses:
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
10 * http://www.opensource.org/licenses/mit-license.php
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
11 * http://www.gnu.org/licenses/gpl.html
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
12 *
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
13 * Pretty print
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
14 *
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
15 * vkbeautify.xml(text [,indent_pattern]);
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
16 * vkbeautify.json(text [,indent_pattern]);
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
17 * vkbeautify.css(text [,indent_pattern]);
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
18 * vkbeautify.sql(text [,indent_pattern]);
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
19 *
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
20 * @text - String; text to beatufy;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
21 * @indent_pattern - Integer | String;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
22 * Integer: number of white spaces;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
23 * String: character string to visualize indentation ( can also be a set of white spaces )
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
24 * Minify
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
25 *
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
26 * vkbeautify.xmlmin(text [,preserve_comments]);
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
27 * vkbeautify.jsonmin(text);
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
28 * vkbeautify.cssmin(text [,preserve_comments]);
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
29 * vkbeautify.sqlmin(text);
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
30 *
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
31 * @text - String; text to minify;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
32 * @preserve_comments - Bool; [optional];
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
33 * Set this flag to true to prevent removing comments from @text ( minxml and mincss functions only. )
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
34 *
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
35 * Examples:
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
36 * vkbeautify.xml(text); // pretty print XML
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
37 * vkbeautify.json(text, 4 ); // pretty print JSON
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
38 * vkbeautify.css(text, '. . . .'); // pretty print CSS
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
39 * vkbeautify.sql(text, '----'); // pretty print SQL
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
40 *
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
41 * vkbeautify.xmlmin(text, true);// minify XML, preserve comments
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
42 * vkbeautify.jsonmin(text);// minify JSON
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
43 * vkbeautify.cssmin(text);// minify CSS, remove comments ( default )
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
44 * vkbeautify.sqlmin(text);// minify SQL
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
45 *
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
46 */
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
47
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
48 (function() {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
49
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
50 function createShiftArr(step) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
51
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
52 var space = ' ';
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
53
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
54 if ( isNaN(parseInt(step)) ) { // argument is string
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
55 space = step;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
56 } else { // argument is integer
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
57 switch(step) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
58 case 1: space = ' '; break;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
59 case 2: space = ' '; break;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
60 case 3: space = ' '; break;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
61 case 4: space = ' '; break;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
62 case 5: space = ' '; break;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
63 case 6: space = ' '; break;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
64 case 7: space = ' '; break;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
65 case 8: space = ' '; break;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
66 case 9: space = ' '; break;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
67 case 10: space = ' '; break;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
68 case 11: space = ' '; break;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
69 case 12: space = ' '; break;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
70 }
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
71 }
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
72
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
73 var shift = ['\n']; // array of shifts
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
74 for(ix=0;ix<100;ix++){
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
75 shift.push(shift[ix]+space);
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
76 }
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
77 return shift;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
78 }
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
79
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
80 function vkbeautify(){
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
81 this.step = ' '; // 4 spaces
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
82 this.shift = createShiftArr(this.step);
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
83 };
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
84
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
85 vkbeautify.prototype.xml = function(text,step) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
86
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
87 var ar = text.replace(/>\s{0,}</g,"><").replace(/</g,"~::~<").split('~::~'),
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
88 len = ar.length,
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
89 inComment = false,
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
90 deep = 0,
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
91 str = '',
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
92 ix = 0,
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
93 shift = step ? createShiftArr(step) : this.shift;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
94
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
95 for(ix=0;ix<len;ix++) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
96 // start comment or <![CDATA[...]]> or <!DOCTYPE //
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
97 if(ar[ix].search(/<!/) > -1) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
98 str += shift[deep]+ar[ix];
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
99 inComment = true;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
100 // end comment or <![CDATA[...]]> //
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
101 if(ar[ix].search(/-->/) > -1 || ar[ix].search(/\]>/) > -1 || ar[ix].search(/!DOCTYPE/) > -1 ) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
102 inComment = false;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
103 }
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
104 } else
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
105 // end comment or <![CDATA[...]]> //
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
106 if(ar[ix].search(/-->/) > -1 || ar[ix].search(/\]>/) > -1) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
107 str += ar[ix];
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
108 inComment = false;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
109 } else
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
110 // <elm></elm> //
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
111 if( /^<\w/.exec(ar[ix-1]) && /^<\/\w/.exec(ar[ix]) &&
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
112 /^<[\w:\-\.\,]+/.exec(ar[ix-1]) == /^<\/[\w:\-\.\,]+/.exec(ar[ix])[0].replace('/','')) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
113 str += ar[ix];
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
114 if(!inComment) deep--;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
115 } else
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
116 // <elm> //
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
117 if(ar[ix].search(/<\w/) > -1 && ar[ix].search(/<\//) == -1 && ar[ix].search(/\/>/) == -1 ) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
118 str = !inComment ? str += shift[deep++]+ar[ix] : str += ar[ix];
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
119 } else
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
120 // <elm>...</elm> //
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
121 if(ar[ix].search(/<\w/) > -1 && ar[ix].search(/<\//) > -1) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
122 str = !inComment ? str += shift[deep]+ar[ix] : str += ar[ix];
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
123 } else
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
124 // </elm> //
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
125 if(ar[ix].search(/<\//) > -1) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
126 str = !inComment ? str += shift[--deep]+ar[ix] : str += ar[ix];
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
127 } else
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
128 // <elm/> //
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
129 if(ar[ix].search(/\/>/) > -1 ) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
130 str = !inComment ? str += shift[deep]+ar[ix] : str += ar[ix];
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
131 } else
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
132 // <? xml ... ?> //
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
133 if(ar[ix].search(/<\?/) > -1) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
134 str += shift[deep]+ar[ix];
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
135 } else {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
136 str += ar[ix];
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
137 }
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
138 }
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
139
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
140 return (str[0] == '\n') ? str.slice(1) : str;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
141 }
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
142
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
143 vkbeautify.prototype.json = function(text,step) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
144
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
145 var ar = this.jsonmin(text).replace(/\{/g,"~::~{~::~")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
146 .replace(/\[/g,"[~::~")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
147 .replace(/\}/g,"~::~}")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
148 .replace(/\]/g,"~::~]")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
149 .replace(/\"\,/g,'",~::~')
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
150 .replace(/\,\"/g,',~::~"')
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
151 .replace(/\]\,/g,'],~::~')
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
152 .replace(/~::~\s{0,}~::~/g,"~::~")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
153 .split('~::~'),
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
154
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
155 len = ar.length,
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
156 deep = 0,
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
157 str = '',
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
158 ix = 0,
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
159 shift = step ? createShiftArr(step) : this.shift;;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
160
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
161 for(ix=0;ix<len;ix++) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
162 if( /\{/.exec(ar[ix])) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
163 str += shift[deep++]+ar[ix];
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
164 } else
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
165 if( /\[/.exec(ar[ix])) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
166 str += shift[deep++]+ar[ix];
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
167 } else
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
168 if( /\]/.exec(ar[ix])) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
169 str += shift[--deep]+ar[ix];
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
170 } else
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
171 if( /\}/.exec(ar[ix])) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
172 str += shift[--deep]+ar[ix];
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
173 } else {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
174 str += shift[deep]+ar[ix];
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
175 }
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
176 }
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
177 return str.replace(/^\n{1,}/,'');
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
178 }
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
179
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
180 vkbeautify.prototype.css = function(text, step) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
181
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
182 var ar = text.replace(/\s{1,}/g,' ')
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
183 .replace(/\{/g,"{~::~")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
184 .replace(/\}/g,"~::~}~::~")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
185 .replace(/\;/g,";~::~")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
186 .replace(/\/\*/g,"~::~/*")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
187 .replace(/\*\//g,"*/~::~")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
188 .replace(/~::~\s{0,}~::~/g,"~::~")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
189 .split('~::~'),
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
190 len = ar.length,
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
191 deep = 0,
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
192 str = '',
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
193 ix = 0,
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
194 shift = step ? createShiftArr(step) : this.shift;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
195
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
196 for(ix=0;ix<len;ix++) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
197
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
198 if( /\{/.exec(ar[ix])) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
199 str += shift[deep++]+ar[ix];
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
200 } else
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
201 if( /\}/.exec(ar[ix])) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
202 str += shift[--deep]+ar[ix];
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
203 } else
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
204 if( /\*\\/.exec(ar[ix])) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
205 str += shift[deep]+ar[ix];
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
206 }
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
207 else {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
208 str += shift[deep]+ar[ix];
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
209 }
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
210 }
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
211 return str.replace(/^\n{1,}/,'');
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
212 }
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
213
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
214 //----------------------------------------------------------------------------
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
215
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
216 function isSubquery(str, parenthesisLevel) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
217 return parenthesisLevel - (str.replace(/\(/g,'').length - str.replace(/\)/g,'').length )
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
218 }
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
219
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
220 function split_sql(str, tab) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
221
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
222 return str.replace(/\s{1,}/g," ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
223
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
224 .replace(/ AND /ig,"~::~"+tab+tab+"AND ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
225 .replace(/ BETWEEN /ig,"~::~"+tab+"BETWEEN ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
226 .replace(/ CASE /ig,"~::~"+tab+"CASE ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
227 .replace(/ ELSE /ig,"~::~"+tab+"ELSE ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
228 .replace(/ END /ig,"~::~"+tab+"END ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
229 .replace(/ FROM /ig,"~::~FROM ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
230 .replace(/ GROUP\s{1,}BY/ig,"~::~GROUP BY ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
231 .replace(/ HAVING /ig,"~::~HAVING ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
232 //.replace(/ IN /ig,"~::~"+tab+"IN ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
233 .replace(/ IN /ig," IN ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
234
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
235 .replace(/ JOIN /ig,"~::~JOIN ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
236 .replace(/ CROSS~::~{1,}JOIN /ig,"~::~CROSS JOIN ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
237 .replace(/ INNER~::~{1,}JOIN /ig,"~::~INNER JOIN ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
238 .replace(/ LEFT~::~{1,}JOIN /ig,"~::~LEFT JOIN ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
239 .replace(/ RIGHT~::~{1,}JOIN /ig,"~::~RIGHT JOIN ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
240
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
241 .replace(/ ON /ig,"~::~"+tab+"ON ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
242 .replace(/ OR /ig,"~::~"+tab+tab+"OR ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
243 .replace(/ ORDER\s{1,}BY/ig,"~::~ORDER BY ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
244 .replace(/ OVER /ig,"~::~"+tab+"OVER ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
245
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
246 .replace(/\(\s{0,}SELECT /ig,"~::~(SELECT ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
247 .replace(/\)\s{0,}SELECT /ig,")~::~SELECT ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
248
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
249 .replace(/ THEN /ig," THEN~::~"+tab+"")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
250 .replace(/ UNION /ig,"~::~UNION~::~")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
251 .replace(/ USING /ig,"~::~USING ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
252 .replace(/ WHEN /ig,"~::~"+tab+"WHEN ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
253 .replace(/ WHERE /ig,"~::~WHERE ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
254 .replace(/ WITH /ig,"~::~WITH ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
255
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
256 //.replace(/\,\s{0,}\(/ig,",~::~( ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
257 //.replace(/\,/ig,",~::~"+tab+tab+"")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
258
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
259 .replace(/ ALL /ig," ALL ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
260 .replace(/ AS /ig," AS ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
261 .replace(/ ASC /ig," ASC ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
262 .replace(/ DESC /ig," DESC ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
263 .replace(/ DISTINCT /ig," DISTINCT ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
264 .replace(/ EXISTS /ig," EXISTS ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
265 .replace(/ NOT /ig," NOT ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
266 .replace(/ NULL /ig," NULL ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
267 .replace(/ LIKE /ig," LIKE ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
268 .replace(/\s{0,}SELECT /ig,"SELECT ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
269
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
270 .replace(/~::~{1,}/g,"~::~")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
271 .split('~::~');
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
272 }
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
273
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
274 vkbeautify.prototype.sql = function(text,step) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
275
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
276 var ar_by_quote = text.replace(/\s{1,}/g," ")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
277 .replace(/\'/ig,"~::~\'")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
278 .split('~::~'),
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
279 len = ar_by_quote.length,
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
280 ar = [],
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
281 deep = 0,
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
282 tab = this.step,//+this.step,
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
283 inComment = true,
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
284 inQuote = false,
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
285 parenthesisLevel = 0,
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
286 str = '',
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
287 ix = 0,
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
288 shift = step ? createShiftArr(step) : this.shift;;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
289
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
290 for(ix=0;ix<len;ix++) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
291 if(ix%2) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
292 ar = ar.concat(ar_by_quote[ix]);
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
293 } else {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
294 ar = ar.concat(split_sql(ar_by_quote[ix], tab) );
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
295 }
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
296 }
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
297
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
298 len = ar.length;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
299 for(ix=0;ix<len;ix++) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
300
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
301 parenthesisLevel = isSubquery(ar[ix], parenthesisLevel);
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
302
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
303 if( /\s{0,}\s{0,}SELECT\s{0,}/.exec(ar[ix])) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
304 ar[ix] = ar[ix].replace(/\,/g,",\n"+tab+tab+"")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
305 }
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
306
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
307 if( /\s{0,}\(\s{0,}SELECT\s{0,}/.exec(ar[ix])) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
308 deep++;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
309 str += shift[deep]+ar[ix];
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
310 } else
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
311 if( /\'/.exec(ar[ix]) ) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
312 if(parenthesisLevel<1 && deep) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
313 deep--;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
314 }
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
315 str += ar[ix];
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
316 }
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
317 else {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
318 str += shift[deep]+ar[ix];
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
319 if(parenthesisLevel<1 && deep) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
320 deep--;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
321 }
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
322 }
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
323 var junk = 0;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
324 }
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
325
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
326 str = str.replace(/^\n{1,}/,'').replace(/\n{1,}/g,"\n");
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
327 return str;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
328 }
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
329
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
330
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
331 vkbeautify.prototype.xmlmin = function(text, preserveComments) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
332
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
333 var str = preserveComments ? text
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
334 : text.replace(/\<![ \r\n\t]*(--([^\-]|[\r\n]|-[^\-])*--[ \r\n\t]*)\>/g,"");
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
335 return str.replace(/>\s{0,}</g,"><");
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
336 }
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
337
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
338 vkbeautify.prototype.jsonmin = function(text) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
339
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
340 return text.replace(/\s{0,}\{\s{0,}/g,"{")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
341 .replace(/\s{0,}\[$/g,"[")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
342 .replace(/\[\s{0,}/g,"[")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
343 .replace(/:\s{0,}\[/g,':[')
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
344 .replace(/\s{0,}\}\s{0,}/g,"}")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
345 .replace(/\s{0,}\]\s{0,}/g,"]")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
346 .replace(/\"\s{0,}\,/g,'",')
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
347 .replace(/\,\s{0,}\"/g,',"')
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
348 .replace(/\"\s{0,}:/g,'":')
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
349 .replace(/:\s{0,}\"/g,':"')
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
350 .replace(/:\s{0,}\[/g,':[')
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
351 .replace(/\,\s{0,}\[/g,',[')
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
352 .replace(/\,\s{2,}/g,', ')
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
353 .replace(/\]\s{0,},\s{0,}\[/g,'],[');
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
354 }
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
355
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
356 vkbeautify.prototype.cssmin = function(text, preserveComments) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
357
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
358 var str = preserveComments ? text
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
359 : text.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"") ;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
360
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
361 return str.replace(/\s{1,}/g,' ')
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
362 .replace(/\{\s{1,}/g,"{")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
363 .replace(/\}\s{1,}/g,"}")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
364 .replace(/\;\s{1,}/g,";")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
365 .replace(/\/\*\s{1,}/g,"/*")
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
366 .replace(/\*\/\s{1,}/g,"*/");
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
367 }
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
368
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
369 vkbeautify.prototype.sqlmin = function(text) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
370 return text.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")");
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
371 }
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
372
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
373 window.vkbeautify = new vkbeautify();
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
374
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
375 })();
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
376