-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
127 lines (120 loc) · 5.31 KB
/
Copy pathscript.js
File metadata and controls
127 lines (120 loc) · 5.31 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/**
* Convert a HTML code into it's correspondent BBCode
* @param {html} input the Cell to convert.
* @return The converted BBCode text.
* @customfunction
*/
function HTMLTOBBCODE(html) {
// Replace HTML tags with BBCode equivalents
html = html.replace(/<b(.*?)>(.*?)<\/b>/gmi, '[b]$2[/b]');
html = html.replace(/<strong(.*?)>(.*?)<\/strong>/gmi, '[b]$2[/b]');
html = html.replace(/<i(.*?)>(.*?)<\/i>/gmi, '[i]$2[/i]');
html = html.replace(/<em(.*?)>(.*?)<\/em>/gmi, '[i]$2[/i]');
html = html.replace(/<u(.*?)>(.*?)<\/u>/gmi, '[u]$2[/u]');
html = html.replace(/<s(.*?)>(.*?)<\/s>/gmi, '[s]$2[/s]');
html = html.replace(/<blockquote(.*?)>(.*?)<\/blockquote>/gmi, '[quote]$2[/quote]');
html = html.replace(/<img(.*?)src="(.*?)"(.*?)>/gmi, '[img]$2[/img]');
html = html.replace(/<a(.*?)href="(.*?)"(.*?)>(.*?)<\/a>/gmi, '[url=$2]$4[/url]');
html = html.replace(/<ul(.*?)>/gmi, '[list]');
html = html.replace(/<\/ul>/gmi, '[/list]');
html = html.replace(/<li(.*?)>(.*?)<\/li>/gmi, '[*]$2');
html = html.replace(/<ol(.*?)>/gmi, '[list=1]');
html = html.replace(/<\/ol>/gmi, '[/list]');
html = html.replace(/<table(.*?)>(.*?)<\/table>/gmi, '[table]$2[/table]');
html = html.replace(/<tr(.*?)>(.*?)<\/tr>/gmi, '[tr]$2[/tr]');
html = html.replace(/<td(.*?)>(.*?)<\/td>/gmi, '[td]$2[/td]');
html = html.replace(/<th(.*?)>(.*?)<\/th>/gmi, '[th]$2[/th]');
html = html.replace(/<h1(.*?)>(.*?)<\/h1>/gmi, '[size=6]$2[/size]');
html = html.replace(/<h2(.*?)>(.*?)<\/h2>/gmi, '[size=5]$2[/size]');
html = html.replace(/<h3(.*?)>(.*?)<\/h3>/gmi, '[size=4]$2[/size]');
html = html.replace(/<h4(.*?)>(.*?)<\/h4>/gmi, '[size=3]$2[/size]');
html = html.replace(/<h5(.*?)>(.*?)<\/h5>/gmi, '[size=3]$1[/size]');
html = html.replace(/<h6(.*?)>(.*?)<\/h6>/gmi, '[size=3]$1[/size]');
// Replace <p></p>, <span>, <br> and other tags with nothing
html = html.replace(/<p(.*?)>(.*?)<\/p>/gmi, '$2\n');
html = html.replace(/<o:p(.*?)>(.*?)<\/o:p>/gmi, '$2\n'); //office namespace
html = html.replace(/<p>/gi, '');
html = html.replace(/<\/p>/gi, '\n\n');
html = html.replace(/<br \/>/gi, '\n');
html = html.replace(/<br(.*?)>/gi, '\n');
html = html.replace(/<span(.*?)>(.*?)<\/span>/gmi, '$2');
html = html.replace(/<span(.*?)>/gi, '');
html = html.replace(/<\/span>/gi, '');
html = html.replace(/<div(.*?)>(.*?)<\/div>/gmi, '$2');
html = html.replace(/<div(.*?)>/gi, '');
html = html.replace(/<\/div>/gi, '');
html = html.replace(/<font(.*?)>/gi, '');
html = html.replace(/<\/font>/gi, '');
html = html.replace(/<tbody(.*?)>/gi, '');
html = html.replace(/<\/tbody>/gi, '');
// Replace dashes and dots characters
html = html.replace(/—/gi, '—');
html = html.replace(/–/gi, '–');
html = html.replace(/·/gi, '·');
html = html.replace(/•/gi, '•');
//Unusual characters
html = html.replace(/✓/gi, '✓');
//Converts hexadecimal HTML entities
html = html.replace(/&#(\d+);/g, ((match, dec) => `${String.fromCharCode(dec)}`));
// Replace HTML entities with their text equivalents
html = html.replace(/ /gi, ' ');
html = html.replace(/</gi, '<');
html = html.replace(/>/gi, '>');
html = html.replace(/"/gi, '"');
html = html.replace(/'/gi, "'");
html = html.replace(/‘/gi, "‘");
html = html.replace(/’/gi, "’");
html = html.replace(/‚/gi, "‚");
html = html.replace(/“/gi, "“");
html = html.replace(/”/gi, "”");
html = html.replace(/ç/g, 'ç');
html = html.replace(/Ç/g, 'Ç');
html = html.replace(/á/g, 'á');
html = html.replace(/à/g, 'à');
html = html.replace(/Á/g, 'Á');
html = html.replace(/é/g, 'é');
html = html.replace(/É/g, 'É');
html = html.replace(/í/g, 'í');
html = html.replace(/Í/g, 'Í');
html = html.replace(/ó/g, 'ó');
html = html.replace(/Ó/g, 'Ó');
html = html.replace(/ú/g, 'ú');
html = html.replace(/Ú/g, 'Ú');
html = html.replace(/ã/g, 'ã');
html = html.replace(/Ã/g, 'Ã');
html = html.replace(/õ/g, 'õ');
html = html.replace(/Õ/g, 'Õ');
html = html.replace(/ñ/g, 'ñ');
html = html.replace(/Ñ/g, 'Ñ');
html = html.replace(/â/g, 'â');
html = html.replace(/Â/g, 'Â');
html = html.replace(/ê/g, 'ê');
html = html.replace(/Ê/g, 'Ê');
html = html.replace(/î/g, 'î');
html = html.replace(/Î/g, 'Î');
html = html.replace(/ô/g, 'ô');
html = html.replace(/Ô/g, 'Ô');
html = html.replace(/°/gi, '°');
html = html.replace(/ª/gi, 'ª');
html = html.replace(/º/gi, 'º');
html = html.replace(/ø/gi, 'ø');
html = html.replace(/Ø/gi, 'Ø');
html = html.replace(/&/gi, '&');
html = html.replace(/ /gi, ' ');
return html;
}
/**
* Decode HTML entities in a range - eg.: "SheetName!A1:A", between quotes.
* @param {range} input the range to decode, eg.: "SheetName!A1:A", between quotes.
* @return The converted text.
* @customfunction
*/
function HTMLTOBBCODERANGE(range) {
let rangeValues = SpreadsheetApp.getActive().getRange(range).getValues();
var valuesArray = [];
rangeValues.forEach(function(item,i){
var itemR = HTMLTOBBCODE(item[0]);
valuesArray.push(itemR);
});
return valuesArray;
}