forked from Blueprinter/Update-Apps-Script
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGS_Crunch_HTML.gs
More file actions
75 lines (59 loc) · 2.54 KB
/
Copy pathGS_Crunch_HTML.gs
File metadata and controls
75 lines (59 loc) · 2.54 KB
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
65
66
67
68
69
70
71
72
73
74
75
function crunch_HTML_File(objOfData, srcFileData) {
var cache,hazScrplet,howManyLoops,rawContent,rgX_pttrn,tempStr;
//cache = CacheService.getScriptCache();
Logger.log('Running crunch_HTML_File: ' + objOfData.idRemoveComments)
if (objOfData.idRemoveComments) {
try{
//howManyLoops = cache.get('loops');
//if (!howManyLoops) {howManyLoops===0};
//howManyLoops = Number(howManyLoops)+1;
//howManyLoops = howManyLoops.toString();
//cache.put('loops', howManyLoops)
//if (howManyLoops === '1') {
//ll('srcFileData one',srcFileData)
//};
hazScrplet = srcFileData.indexOf("<?") !== -1;
//ll('hazScrplet',hazScrplet);
if (!hazScrplet) {
tempStr = HtmlService.createHtmlOutput(srcFileData).getContent();//This strips out the comments
if (objOfData.idLinesBetweenGS) {//If the check box was checked to remove blank lines
tempStr = fncRemoveBlankLines(tempStr);
}
return tempStr;
}
//first replace the beginning scriptlet characters <? with zq*~
rgX_pttrn = new RegExp("\<\\?","g");
//ll('got here');
rawContent = srcFileData.replace(rgX_pttrn,'"zqqpz');//Now there will not be an error evaluating HTML
//Must put double quotation marks at front so that it is seen as text
rgX_pttrn = new RegExp("\\?\>","g");
rawContent = rawContent.replace(rgX_pttrn,'qqpzzz"');//Must replace the ending ?> part of scriptlet
//if (howManyLoops === '1') {
//ll('rawContent one',rawContent)
//};
rawContent = HtmlService.createHtmlOutput(rawContent).getContent();//This strips out the comments
//if (howManyLoops === '1') {
//ll('rawContent two',rawContent)
//};
rgX_pttrn = new RegExp('"zqqpz',"g");
tempStr = rawContent.replace(rgX_pttrn,'<?');//Put the scriptlet beginning back in
rgX_pttrn = new RegExp('qqpzzz"',"g");
tempStr = tempStr.replace(rgX_pttrn,'?>');//Put the scriptlet ending back in
//if (howManyLoops === '1') {
//ll('tempStr',tempStr)
//};
}catch(e) {//
//ll('error creating html output', e.message);
}
//ll('tempStr',tempStr)
if (!tempStr) {return srcFileData;}
srcFileData = tempStr;
};
if (objOfData.idLinesBetweenGS) {
//Logger.log('passed test to delete empty lines')
tempStr = fncRemoveBlankLines(srcFileData);
if (!tempStr || tempStr === " ") {return "//Nothing Left"};
srcFileData = tempStr;
}
return srcFileData;
};