1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
var MyToolBox = Editor.addMenu("ToolBox");
MyToolBox.addItem({
text : "CSSEncode",
cmd : function () {
var unencoded = Editor.currentView.text
var encoded = CSSencode(unencoded);
Editor.currentView.text = encoded;
}
});
MyToolBox.addItem({
text : "CSSDecode",
cmd : function () {
var encoded = Editor.currentView.text
var unencoded = CSSdecode(encoded);
Editor.currentView.text = unencoded;
}
});
MyToolBox.addItem({
text : "URIEncode",
cmd : function () {
var unencoded = Editor.currentView.text
var encoded = encodeURIComponent(unencoded);
Editor.currentView.text = encoded;
}
});
MyToolBox.addItem({
text : "URIDecode",
cmd : function () {
var encoded = Editor.currentView.text
var unencoded = decodeURIComponent(encoded);
Editor.currentView.text = unencoded;
}
});
function CSSencode(code)
{
code = code.replace(/\n/ig,'');
code = code.replace(/(\s){2,}/ig,'$1');
code = code.replace(/\t/ig,'');
code = code.replace(/\n\}/ig,'\}');
code = code.replace(/\n\{\s*/ig,'\{');
code = code.replace(/(\S)\s*\}/ig,'$1\}');
code = code.replace(/(\S)\s*\{/ig,'$1\{');
code = code.replace(/\{\s*(\S)/ig,'\{$1');
return code;
}
function CSSdecode(code)
{
code = code.replace(/(\s){2,}/ig,'$1');
code = code.replace(/(\S)\s*\{/ig,'$1 {');
code = code.replace(/\*\/(.[^\}\{]*)}/ig,'\*\/\n$1}');
code = code.replace(/\/\*/ig,'\n\/\*');
code = code.replace(/;\s*(\S)/ig,';\n\t$1');
code = code.replace(/\}\s*(\S)/ig,'\}\n$1');
code = code.replace(/\n\s*\}/ig,'\n\}');
code = code.replace(/\{\s*(\S)/ig,'\{\n\t$1');
code = code.replace(/(\S)\s*\*\//ig,'$1\*\/');
code = code.replace(/\*\/\s*([^\}\{]\S)/ig,'\*\/\n\t$1');
code = code.replace(/(\S)\}/ig,'$1\n\}');
code = code.replace(/(\n){2,}/ig,'\n');
code = code.replace(/:/ig,': ');
code = code.replace(/ /ig,' ');
return code;
}
|