mercury-rails 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +81 -50
- data/VERSION +1 -1
- data/app/assets/javascripts/mercury/dialog.js.coffee +4 -4
- data/app/assets/javascripts/mercury/dialogs/backcolor.js.coffee +3 -3
- data/app/assets/javascripts/mercury/dialogs/forecolor.js.coffee +3 -3
- data/app/assets/javascripts/mercury/dialogs/formatblock.js.coffee +1 -1
- data/app/assets/javascripts/mercury/dialogs/objectspanel.js.coffee +3 -3
- data/app/assets/javascripts/mercury/dialogs/style.js.coffee +1 -1
- data/app/assets/javascripts/mercury/history_buffer.js.coffee +2 -2
- data/app/assets/javascripts/mercury/mercury.js.coffee +47 -54
- data/app/assets/javascripts/mercury/modal.js.coffee +13 -13
- data/app/assets/javascripts/mercury/modals/htmleditor.js.coffee +2 -2
- data/app/assets/javascripts/mercury/modals/insertcharacter.js.coffee +2 -2
- data/app/assets/javascripts/mercury/modals/insertlink.js.coffee +7 -7
- data/app/assets/javascripts/mercury/modals/insertmedia.js.coffee +5 -5
- data/app/assets/javascripts/mercury/modals/insertsnippet.js.coffee +2 -2
- data/app/assets/javascripts/mercury/modals/inserttable.js.coffee +14 -15
- data/app/assets/javascripts/mercury/native_extensions.js.coffee +2 -1
- data/app/assets/javascripts/mercury/page_editor.js.coffee +27 -27
- data/app/assets/javascripts/mercury/palette.js.coffee +6 -6
- data/app/assets/javascripts/mercury/panel.js.coffee +4 -4
- data/app/assets/javascripts/mercury/region.js.coffee +9 -9
- data/app/assets/javascripts/mercury/regions/editable.js.coffee +71 -71
- data/app/assets/javascripts/mercury/regions/markupable.js.coffee +51 -42
- data/app/assets/javascripts/mercury/regions/snippetable.js.coffee +7 -8
- data/app/assets/javascripts/mercury/select.js.coffee +8 -8
- data/app/assets/javascripts/mercury/snippet.js.coffee +6 -6
- data/app/assets/javascripts/mercury/snippet_toolbar.js.coffee +7 -7
- data/app/assets/javascripts/mercury/statusbar.js.coffee +7 -3
- data/app/assets/javascripts/mercury/table_editor.js.coffee +24 -24
- data/app/assets/javascripts/mercury/toolbar.button.js.coffee +20 -21
- data/app/assets/javascripts/mercury/toolbar.button_group.js.coffee +2 -2
- data/app/assets/javascripts/mercury/toolbar.expander.js.coffee +9 -9
- data/app/assets/javascripts/mercury/toolbar.js.coffee +12 -13
- data/app/assets/javascripts/mercury/tooltip.js.coffee +7 -7
- data/app/assets/javascripts/mercury/uploader.js.coffee +12 -13
- data/app/assets/javascripts/mercury_loader.js +98 -0
- data/app/assets/stylesheets/mercury/modal.scss +5 -5
- data/app/assets/stylesheets/mercury/toolbar.scss +62 -64
- data/app/views/layouts/mercury.html.haml +0 -4
- data/app/views/mercury/modals/character.html.haml +1 -1
- data/app/views/mercury/modals/htmleditor.html.haml +1 -1
- data/app/views/mercury/modals/table.html.haml +10 -10
- data/config/routes.rb +2 -2
- data/mercury-rails.gemspec +17 -20
- data/spec/javascripts/mercury/dialogs/backcolor_spec.js.coffee +3 -3
- data/spec/javascripts/mercury/dialogs/forecolor_spec.js.coffee +3 -3
- data/spec/javascripts/mercury/dialogs/objectspanel_spec.js.coffee +3 -3
- data/spec/javascripts/mercury/modals/htmleditor_spec.js.coffee +4 -4
- data/spec/javascripts/mercury/modals/insertcharacter_spec.js.coffee +2 -2
- data/spec/javascripts/mercury/modals/insertlink_spec.js.coffee +10 -10
- data/spec/javascripts/mercury/modals/insertmedia_spec.js.coffee +7 -7
- data/spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee +4 -4
- data/spec/javascripts/mercury/modals/inserttable_spec.js.coffee +17 -17
- data/spec/javascripts/mercury/page_editor_spec.js.coffee +5 -6
- data/spec/javascripts/mercury/region_spec.js.coffee +5 -5
- data/spec/javascripts/mercury/regions/editable_spec.js.coffee +398 -0
- data/spec/javascripts/mercury/regions/snippetable_spec.js.coffee +18 -14
- data/spec/javascripts/mercury/snippet_spec.js.coffee +1 -1
- data/spec/javascripts/mercury/toolbar.button_spec.js.coffee +16 -16
- data/spec/javascripts/templates/mercury/modals/inserttable.html +11 -11
- data/spec/javascripts/templates/mercury/regions/editable.html +3 -0
- data/spec/javascripts/templates/mercury/toolbar.button.html +8 -8
- data/vendor/assets/javascripts/{jquery-ui-1.8.13.sortable.custom.js → jquery-ui-1.8.13.custom.js} +250 -0
- data/vendor/assets/javascripts/jquery.additions.js +151 -0
- data/vendor/assets/javascripts/showdown.js +1254 -1276
- metadata +26 -29
- data/app/assets/javascripts/mercury/websocket.js.coffee +0 -34
- data/spec/javascripts/mercury/regions/_editable_.js.coffee +0 -0
- data/vendor/assets/javascripts/jquery-ui-1.8.13.custom.min.js +0 -249
- data/vendor/assets/javascripts/jquery.easing.js +0 -173
- data/vendor/assets/javascripts/jquery.json2.js +0 -178
- data/vendor/assets/javascripts/jquery.serialize_object.js +0 -16
- data/vendor/assets/javascripts/jquery.ujs.js +0 -289
@@ -0,0 +1,151 @@
|
|
1
|
+
/*
|
2
|
+
* jQuery serializeObject Plugin
|
3
|
+
*
|
4
|
+
*/
|
5
|
+
(function($) {
|
6
|
+
$.fn.serializeObject = function() {
|
7
|
+
var o = {};
|
8
|
+
var a = this.serializeArray();
|
9
|
+
jQuery.each(a, function() {
|
10
|
+
if (o[this.name] !== undefined) {
|
11
|
+
if (!o[this.name].push) o[this.name] = [o[this.name]];
|
12
|
+
o[this.name].push(this.value || '');
|
13
|
+
} else {
|
14
|
+
o[this.name] = this.value || '';
|
15
|
+
}
|
16
|
+
});
|
17
|
+
return o;
|
18
|
+
};
|
19
|
+
})(jQuery);
|
20
|
+
|
21
|
+
/*
|
22
|
+
* jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
|
23
|
+
*
|
24
|
+
* Uses the built in easing capabilities added In jQuery 1.1 to offer multiple easing options
|
25
|
+
*
|
26
|
+
* TERMS OF USE - jQuery Easing
|
27
|
+
*
|
28
|
+
* Open source under the BSD License.
|
29
|
+
*
|
30
|
+
* Copyright © 2008 George McGinley Smith
|
31
|
+
* All rights reserved.
|
32
|
+
*
|
33
|
+
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
34
|
+
* following conditions are met:
|
35
|
+
*
|
36
|
+
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following
|
37
|
+
* disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
38
|
+
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
39
|
+
*
|
40
|
+
* Neither the name of the author nor the names of contributors may be used to endorse or promote products derived from
|
41
|
+
* this software without specific prior written permission.
|
42
|
+
*
|
43
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
44
|
+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
45
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
46
|
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
47
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
48
|
+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
49
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
50
|
+
*/
|
51
|
+
jQuery.extend(jQuery.easing, {
|
52
|
+
easeInSine: function (x, t, b, c, d) {
|
53
|
+
return -c * Math.cos(t / d * (Math.PI / 2)) + c + b
|
54
|
+
},
|
55
|
+
easeOutSine: function (x, t, b, c, d) {
|
56
|
+
return c * Math.sin(t / d * (Math.PI / 2)) + b
|
57
|
+
},
|
58
|
+
easeInOutSine: function (x, t, b, c, d) {
|
59
|
+
return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b
|
60
|
+
}
|
61
|
+
});
|
62
|
+
|
63
|
+
/*
|
64
|
+
* jQuery JSON Plugin version: 2.1 (2009-08-14)
|
65
|
+
*
|
66
|
+
* This document is licensed as free software under the terms of the MIT License:
|
67
|
+
* http://www.opensource.org/licenses/mit-license.php
|
68
|
+
*
|
69
|
+
* Brantley Harris wrote this plugin. It is based somewhat on the JSON.org website's http://www.json.org/json2.js,
|
70
|
+
* which proclaims: "NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.", a sentiment that I uphold.
|
71
|
+
*
|
72
|
+
* It is also influenced heavily by MochiKit's serializeJSON, which is copyrighted 2005 by Bob Ippolito.
|
73
|
+
*/
|
74
|
+
(function($) {
|
75
|
+
$.toJSON = function(o) {
|
76
|
+
if (typeof(JSON) == 'object' && JSON.stringify) return JSON.stringify(o);
|
77
|
+
|
78
|
+
var type = typeof(o);
|
79
|
+
|
80
|
+
if (o === null) return "null";
|
81
|
+
if (type == "undefined") return undefined;
|
82
|
+
if (type == "number" || type == "boolean") return o + "";
|
83
|
+
if (type == "string") return $.quoteString(o);
|
84
|
+
|
85
|
+
if (type == 'object') {
|
86
|
+
if (typeof(o.toJSON) == "function") return $.toJSON(o.toJSON());
|
87
|
+
|
88
|
+
if (o.constructor === Date) {
|
89
|
+
var year = o.getUTCFullYear();
|
90
|
+
|
91
|
+
var month = o.getUTCMonth() + 1;
|
92
|
+
if (month < 10) month = '0' + month;
|
93
|
+
|
94
|
+
var day = o.getUTCDate();
|
95
|
+
if (day < 10) day = '0' + day;
|
96
|
+
|
97
|
+
var hours = o.getUTCHours();
|
98
|
+
if (hours < 10) hours = '0' + hours;
|
99
|
+
|
100
|
+
var minutes = o.getUTCMinutes();
|
101
|
+
if (minutes < 10) minutes = '0' + minutes;
|
102
|
+
|
103
|
+
var seconds = o.getUTCSeconds();
|
104
|
+
if (seconds < 10) seconds = '0' + seconds;
|
105
|
+
|
106
|
+
var milli = o.getUTCMilliseconds();
|
107
|
+
if (milli < 100) milli = '0' + milli;
|
108
|
+
if (milli < 10) milli = '0' + milli;
|
109
|
+
|
110
|
+
return '"' + year + '-' + month + '-' + day + 'T' + hours + ':' + minutes + ':' + seconds + '.' + milli + 'Z"';
|
111
|
+
}
|
112
|
+
|
113
|
+
if (o.constructor === Array) {
|
114
|
+
var ret = [];
|
115
|
+
for (var i = 0; i < o.length; i++) ret.push($.toJSON(o[i]) || "null");
|
116
|
+
return "[" + ret.join(",") + "]";
|
117
|
+
}
|
118
|
+
|
119
|
+
var pairs = [];
|
120
|
+
for (var k in o) {
|
121
|
+
var name;
|
122
|
+
type = typeof(k);
|
123
|
+
|
124
|
+
if (type == "number") name = '"' + k + '"';
|
125
|
+
else if (type == "string") name = $.quoteString(k);
|
126
|
+
else continue; //skip non-string or number keys
|
127
|
+
|
128
|
+
if (typeof o[k] == "function") continue; //skip pairs where the value is a function.
|
129
|
+
var val = $.toJSON(o[k]);
|
130
|
+
pairs.push(name + ":" + val);
|
131
|
+
}
|
132
|
+
|
133
|
+
return "{" + pairs.join(", ") + "}";
|
134
|
+
}
|
135
|
+
};
|
136
|
+
|
137
|
+
$.quoteString = function(string) {
|
138
|
+
if (string.match(_escapeable)) {
|
139
|
+
return '"' + string.replace(_escapeable, function (a) {
|
140
|
+
var c = _meta[a];
|
141
|
+
if (typeof c === 'string') return c;
|
142
|
+
c = a.charCodeAt();
|
143
|
+
return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16);
|
144
|
+
}) + '"';
|
145
|
+
}
|
146
|
+
return '"' + string + '"';
|
147
|
+
};
|
148
|
+
|
149
|
+
var _escapeable = /["\\\x00-\x1f\x7f-\x9f]/g;
|
150
|
+
var _meta = {'\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"' : '\\"', '\\': '\\\\'};
|
151
|
+
})(jQuery);
|
@@ -81,1282 +81,1260 @@ var Showdown = {};
|
|
81
81
|
//
|
82
82
|
Showdown.converter = function() {
|
83
83
|
|
84
|
-
//
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
var
|
92
|
-
|
93
|
-
//
|
94
|
-
//
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
//
|
100
|
-
//
|
101
|
-
//
|
102
|
-
//
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
g_urls = new Array();
|
111
|
-
g_titles = new Array();
|
112
|
-
g_html_blocks = new Array();
|
113
|
-
|
114
|
-
// attacklab: Replace ~ with ~T
|
115
|
-
// This lets us use tilde as an escape char to avoid md5 hashes
|
116
|
-
// The choice of character is arbitray; anything that isn't
|
84
|
+
// Global hashes, used by various utility routines
|
85
|
+
var g_urls;
|
86
|
+
var g_titles;
|
87
|
+
var g_html_blocks;
|
88
|
+
|
89
|
+
// Used to track when we're inside an ordered or unordered list
|
90
|
+
// (see _ProcessListItems() for details):
|
91
|
+
var g_list_level = 0;
|
92
|
+
|
93
|
+
// Main function. The order in which other subs are called here is
|
94
|
+
// essential. Link and image substitutions need to happen before
|
95
|
+
// _EscapeSpecialCharsWithinTagAttributes(), so that any *'s or _'s in the <a>
|
96
|
+
// and <img> tags get encoded.
|
97
|
+
this.makeHtml = function(text) {
|
98
|
+
|
99
|
+
// Clear the global hashes. If we don't clear these, you get conflicts
|
100
|
+
// from other articles when generating a page which contains more than
|
101
|
+
// one article (e.g. an index page that shows the N most recent
|
102
|
+
// articles):
|
103
|
+
g_urls = new Array();
|
104
|
+
g_titles = new Array();
|
105
|
+
g_html_blocks = new Array();
|
106
|
+
|
107
|
+
// attacklab: Replace ~ with ~T
|
108
|
+
// This lets us use tilde as an escape char to avoid md5 hashes
|
109
|
+
// The choice of character is arbitray; anything that isn't
|
117
110
|
// magic in Markdown will work.
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
}
|
217
|
-
|
218
|
-
var
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
}
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
//
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
//
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
//
|
766
|
-
|
767
|
-
//
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
}
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
//
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
}
|
952
|
-
|
953
|
-
var
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
//
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
//
|
978
|
-
//
|
979
|
-
//
|
980
|
-
//
|
981
|
-
//
|
982
|
-
//
|
983
|
-
//
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
//
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
//
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1136
|
-
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
//
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1219
|
-
|
1220
|
-
//
|
1221
|
-
//
|
1222
|
-
//
|
1223
|
-
//
|
1224
|
-
//
|
1225
|
-
//
|
1226
|
-
//
|
1227
|
-
//
|
1228
|
-
// xample.com
|
1229
|
-
//
|
1230
|
-
//
|
1231
|
-
//
|
1232
|
-
//
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1264
|
-
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1273
|
-
|
1274
|
-
var
|
1275
|
-
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
//
|
1291
|
-
|
1292
|
-
|
1293
|
-
|
1294
|
-
|
1295
|
-
|
1296
|
-
|
1297
|
-
|
1298
|
-
|
1299
|
-
|
1300
|
-
|
1301
|
-
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1305
|
-
|
1306
|
-
//
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
1330
|
-
|
1331
|
-
|
1332
|
-
|
1333
|
-
}
|
1334
|
-
|
1335
|
-
|
1336
|
-
|
1337
|
-
|
1338
|
-
|
1339
|
-
|
1340
|
-
|
1341
|
-
var escapeCharacters = function(text, charsToEscape, afterBackslash) {
|
1342
|
-
// First we have to escape the escape characters so that
|
1343
|
-
// we can build a character class out of them
|
1344
|
-
var regexString = "([" + charsToEscape.replace(/([\[\]\\])/g,"\\$1") + "])";
|
1345
|
-
|
1346
|
-
if (afterBackslash) {
|
1347
|
-
regexString = "\\\\" + regexString;
|
1348
|
-
}
|
1349
|
-
|
1350
|
-
var regex = new RegExp(regexString,"g");
|
1351
|
-
text = text.replace(regex,escapeCharacters_callback);
|
1352
|
-
|
1353
|
-
return text;
|
1354
|
-
}
|
1355
|
-
|
111
|
+
text = text.replace(/~/g, "~T");
|
112
|
+
|
113
|
+
// attacklab: Replace $ with ~D
|
114
|
+
// RegExp interprets $ as a special character
|
115
|
+
// when it's in a replacement string
|
116
|
+
text = text.replace(/\$/g, "~D");
|
117
|
+
|
118
|
+
// Standardize line endings
|
119
|
+
text = text.replace(/\r\n/g, "\n"); // DOS to Unix
|
120
|
+
text = text.replace(/\r/g, "\n"); // Mac to Unix
|
121
|
+
|
122
|
+
// Make sure text begins and ends with a couple of newlines:
|
123
|
+
text = "\n\n" + text + "\n\n";
|
124
|
+
|
125
|
+
// Convert all tabs to spaces.
|
126
|
+
text = _Detab(text);
|
127
|
+
|
128
|
+
// Strip any lines consisting only of spaces and tabs.
|
129
|
+
// This makes subsequent regexen easier to write, because we can
|
130
|
+
// match consecutive blank lines with /\n+/ instead of something
|
131
|
+
// contorted like /[ \t]*\n+/ .
|
132
|
+
text = text.replace(/^[ \t]+$/mg, "");
|
133
|
+
|
134
|
+
// Turn block-level HTML blocks into hash entries
|
135
|
+
text = _HashHTMLBlocks(text);
|
136
|
+
|
137
|
+
// Strip link definitions, store in hashes.
|
138
|
+
text = _StripLinkDefinitions(text);
|
139
|
+
|
140
|
+
text = _RunBlockGamut(text);
|
141
|
+
|
142
|
+
text = _UnescapeSpecialChars(text);
|
143
|
+
|
144
|
+
// attacklab: Restore dollar signs
|
145
|
+
text = text.replace(/~D/g, "$$");
|
146
|
+
|
147
|
+
// attacklab: Restore tildes
|
148
|
+
text = text.replace(/~T/g, "~");
|
149
|
+
|
150
|
+
// ** GFM ** Auto-link URLs and emails
|
151
|
+
text = text.replace(/https?\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!]/g, function(wholeMatch, matchIndex) {
|
152
|
+
var left = text.slice(0, matchIndex), right = text.slice(matchIndex);
|
153
|
+
if (left.match(/<[^>]+$/) && right.match(/^[^>]*>/)) {
|
154
|
+
return wholeMatch
|
155
|
+
}
|
156
|
+
var href = wholeMatch.replace(/^http:\/\/github.com\//, "https://github.com/");
|
157
|
+
return "<a href='" + href + "'>" + wholeMatch + "</a>";
|
158
|
+
});
|
159
|
+
text = text.replace(/[a-z0-9_\-+=.]+@[a-z0-9\-]+(\.[a-z0-9-]+)+/ig, function(wholeMatch) {
|
160
|
+
return "<a href='mailto:" + wholeMatch + "'>" + wholeMatch + "</a>";
|
161
|
+
});
|
162
|
+
|
163
|
+
// ** GFM ** Auto-link sha1 if GitHub.nameWithOwner is defined
|
164
|
+
text = text.replace(/[a-f0-9]{40}/ig, function(wholeMatch, matchIndex) {
|
165
|
+
if (typeof(GitHub) == "undefined" || typeof(GitHub.nameWithOwner) == "undefined") {
|
166
|
+
return wholeMatch;
|
167
|
+
}
|
168
|
+
var left = text.slice(0, matchIndex), right = text.slice(matchIndex);
|
169
|
+
if (left.match(/@$/) || (left.match(/<[^>]+$/) && right.match(/^[^>]*>/))) {
|
170
|
+
return wholeMatch;
|
171
|
+
}
|
172
|
+
return "<a href='http://github.com/" + GitHub.nameWithOwner + "/commit/" + wholeMatch + "'>" + wholeMatch.substring(0, 7) + "</a>";
|
173
|
+
});
|
174
|
+
|
175
|
+
// ** GFM ** Auto-link user@sha1 if GitHub.nameWithOwner is defined
|
176
|
+
text = text.replace(/([a-z0-9_\-+=.]+)@([a-f0-9]{40})/ig, function(wholeMatch, username, sha, matchIndex) {
|
177
|
+
if (typeof(GitHub) == "undefined" || typeof(GitHub.nameWithOwner) == "undefined") {
|
178
|
+
return wholeMatch;
|
179
|
+
}
|
180
|
+
GitHub.repoName = GitHub.repoName || _GetRepoName();
|
181
|
+
var left = text.slice(0, matchIndex), right = text.slice(matchIndex);
|
182
|
+
if (left.match(/\/$/) || (left.match(/<[^>]+$/) && right.match(/^[^>]*>/))) {
|
183
|
+
return wholeMatch;
|
184
|
+
}
|
185
|
+
return "<a href='http://github.com/" + username + "/" + GitHub.repoName + "/commit/" + sha + "'>" + username + "@" + sha.substring(0, 7) + "</a>";
|
186
|
+
});
|
187
|
+
|
188
|
+
// ** GFM ** Auto-link user/repo@sha1
|
189
|
+
text = text.replace(/([a-z0-9_\-+=.]+\/[a-z0-9_\-+=.]+)@([a-f0-9]{40})/ig, function(wholeMatch, repo, sha) {
|
190
|
+
return "<a href='http://github.com/" + repo + "/commit/" + sha + "'>" + repo + "@" + sha.substring(0, 7) + "</a>";
|
191
|
+
});
|
192
|
+
|
193
|
+
// ** GFM ** Auto-link #issue if GitHub.nameWithOwner is defined
|
194
|
+
text = text.replace(/#([0-9]+)/ig, function(wholeMatch, issue, matchIndex) {
|
195
|
+
if (typeof(GitHub) == "undefined" || typeof(GitHub.nameWithOwner) == "undefined") {
|
196
|
+
return wholeMatch;
|
197
|
+
}
|
198
|
+
var left = text.slice(0, matchIndex), right = text.slice(matchIndex);
|
199
|
+
if (left == "" || left.match(/[a-z0-9_\-+=.]$/) || (left.match(/<[^>]+$/) && right.match(/^[^>]*>/))) {
|
200
|
+
return wholeMatch;
|
201
|
+
}
|
202
|
+
return "<a href='http://github.com/" + GitHub.nameWithOwner + "/issues/#issue/" + issue + "'>" + wholeMatch + "</a>";
|
203
|
+
});
|
204
|
+
|
205
|
+
// ** GFM ** Auto-link user#issue if GitHub.nameWithOwner is defined
|
206
|
+
text = text.replace(/([a-z0-9_\-+=.]+)#([0-9]+)/ig, function(wholeMatch, username, issue, matchIndex) {
|
207
|
+
if (typeof(GitHub) == "undefined" || typeof(GitHub.nameWithOwner) == "undefined") {
|
208
|
+
return wholeMatch;
|
209
|
+
}
|
210
|
+
GitHub.repoName = GitHub.repoName || _GetRepoName();
|
211
|
+
var left = text.slice(0, matchIndex), right = text.slice(matchIndex);
|
212
|
+
if (left.match(/\/$/) || (left.match(/<[^>]+$/) && right.match(/^[^>]*>/))) {
|
213
|
+
return wholeMatch;
|
214
|
+
}
|
215
|
+
return "<a href='http://github.com/" + username + "/" + GitHub.repoName + "/issues/#issue/" + issue + "'>" + wholeMatch + "</a>";
|
216
|
+
});
|
217
|
+
|
218
|
+
// ** GFM ** Auto-link user/repo#issue
|
219
|
+
text = text.replace(/([a-z0-9_\-+=.]+\/[a-z0-9_\-+=.]+)#([0-9]+)/ig, function(wholeMatch, repo, issue) {
|
220
|
+
return "<a href='http://github.com/" + repo + "/issues/#issue/" + issue + "'>" + wholeMatch + "</a>";
|
221
|
+
});
|
222
|
+
|
223
|
+
return text;
|
224
|
+
};
|
225
|
+
|
226
|
+
|
227
|
+
var _GetRepoName = function() {
|
228
|
+
return GitHub.nameWithOwner.match(/^.+\/(.+)$/)[1]
|
229
|
+
};
|
230
|
+
|
231
|
+
//
|
232
|
+
// Strips link definitions from text, stores the URLs and titles in
|
233
|
+
// hash references.
|
234
|
+
//
|
235
|
+
var _StripLinkDefinitions = function(text) {
|
236
|
+
|
237
|
+
// Link defs are in the form: ^[id]: url "optional title"
|
238
|
+
|
239
|
+
/*
|
240
|
+
var text = text.replace(/
|
241
|
+
^[ ]{0,3}\[(.+)\]: // id = $1 attacklab: g_tab_width - 1
|
242
|
+
[ \t]*
|
243
|
+
\n? // maybe *one* newline
|
244
|
+
[ \t]*
|
245
|
+
<?(\S+?)>? // url = $2
|
246
|
+
[ \t]*
|
247
|
+
\n? // maybe one newline
|
248
|
+
[ \t]*
|
249
|
+
(?:
|
250
|
+
(\n*) // any lines skipped = $3 attacklab: lookbehind removed
|
251
|
+
["(]
|
252
|
+
(.+?) // title = $4
|
253
|
+
[")]
|
254
|
+
[ \t]*
|
255
|
+
)? // title is optional
|
256
|
+
(?:\n+|$)
|
257
|
+
/gm,
|
258
|
+
function(){...});
|
259
|
+
*/
|
260
|
+
var text = text.replace(/^[ ]{0,3}\[(.+)\]:[ \t]*\n?[ \t]*<?(\S+?)>?[ \t]*\n?[ \t]*(?:(\n*)["(](.+?)[")][ \t]*)?(?:\n+|\Z)/gm, function (wholeMatch, m1, m2, m3, m4) {
|
261
|
+
m1 = m1.toLowerCase();
|
262
|
+
g_urls[m1] = _EncodeAmpsAndAngles(m2); // Link IDs are case-insensitive
|
263
|
+
if (m3) {
|
264
|
+
// Oops, found blank lines, so it's not a title.
|
265
|
+
// Put back the parenthetical statement we stole.
|
266
|
+
return m3 + m4;
|
267
|
+
} else if (m4) {
|
268
|
+
g_titles[m1] = m4.replace(/"/g, """);
|
269
|
+
}
|
270
|
+
|
271
|
+
// Completely remove the definition from the text
|
272
|
+
return "";
|
273
|
+
});
|
274
|
+
|
275
|
+
return text;
|
276
|
+
};
|
277
|
+
|
278
|
+
|
279
|
+
var _HashHTMLBlocks = function(text) {
|
280
|
+
// attacklab: Double up blank lines to reduce lookaround
|
281
|
+
text = text.replace(/\n/g, "\n\n");
|
282
|
+
|
283
|
+
// Hashify HTML blocks:
|
284
|
+
// We only want to do this for block-level HTML tags, such as headers,
|
285
|
+
// lists, and tables. That's because we still want to wrap <p>s around
|
286
|
+
// "paragraphs" that are wrapped in non-block-level tags, such as anchors,
|
287
|
+
// phrase emphasis, and spans. The list of tags we're looking for is
|
288
|
+
// hard-coded:
|
289
|
+
var block_tags_a = "p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del";
|
290
|
+
var block_tags_b = "p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math";
|
291
|
+
|
292
|
+
// First, look for nested blocks, e.g.:
|
293
|
+
// <div>
|
294
|
+
// <div>
|
295
|
+
// tags for inner block must be indented.
|
296
|
+
// </div>
|
297
|
+
// </div>
|
298
|
+
//
|
299
|
+
// The outermost tags must start at the left margin for this to match, and
|
300
|
+
// the inner nested divs must be indented.
|
301
|
+
// We need to do this before the next, more liberal match, because the next
|
302
|
+
// match will start at the first `<div>` and stop at the first `</div>`.
|
303
|
+
|
304
|
+
// attacklab: This regex can be expensive when it fails.
|
305
|
+
/*
|
306
|
+
var text = text.replace(/
|
307
|
+
( // save in $1
|
308
|
+
^ // start of line (with /m)
|
309
|
+
<($block_tags_a) // start tag = $2
|
310
|
+
\b // word break
|
311
|
+
// attacklab: hack around khtml/pcre bug...
|
312
|
+
[^\r]*?\n // any number of lines, minimally matching
|
313
|
+
</\2> // the matching end tag
|
314
|
+
[ \t]* // trailing spaces/tabs
|
315
|
+
(?=\n+) // followed by a newline
|
316
|
+
) // attacklab: there are sentinel newlines at end of document
|
317
|
+
/gm,function(){...}};
|
318
|
+
*/
|
319
|
+
text = text.replace(/^(<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del)\b[^\r]*?\n<\/\2>[ \t]*(?=\n+))/gm, hashElement);
|
320
|
+
|
321
|
+
//
|
322
|
+
// Now match more liberally, simply from `\n<tag>` to `</tag>\n`
|
323
|
+
//
|
324
|
+
|
325
|
+
/*
|
326
|
+
var text = text.replace(/
|
327
|
+
( // save in $1
|
328
|
+
^ // start of line (with /m)
|
329
|
+
<($block_tags_b) // start tag = $2
|
330
|
+
\b // word break
|
331
|
+
// attacklab: hack around khtml/pcre bug...
|
332
|
+
[^\r]*? // any number of lines, minimally matching
|
333
|
+
.*</\2> // the matching end tag
|
334
|
+
[ \t]* // trailing spaces/tabs
|
335
|
+
(?=\n+) // followed by a newline
|
336
|
+
) // attacklab: there are sentinel newlines at end of document
|
337
|
+
/gm,function(){...}};
|
338
|
+
*/
|
339
|
+
text = text.replace(/^(<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math)\b[^\r]*?.*<\/\2>[ \t]*(?=\n+)\n)/gm, hashElement);
|
340
|
+
|
341
|
+
// Special case just for <hr />. It was easier to make a special case than
|
342
|
+
// to make the other regex more complicated.
|
343
|
+
|
344
|
+
/*
|
345
|
+
text = text.replace(/
|
346
|
+
( // save in $1
|
347
|
+
\n\n // Starting after a blank line
|
348
|
+
[ ]{0,3}
|
349
|
+
(<(hr) // start tag = $2
|
350
|
+
\b // word break
|
351
|
+
([^<>])*? //
|
352
|
+
\/?>) // the matching end tag
|
353
|
+
[ \t]*
|
354
|
+
(?=\n{2,}) // followed by a blank line
|
355
|
+
)
|
356
|
+
/g,hashElement);
|
357
|
+
*/
|
358
|
+
text = text.replace(/(\n[ ]{0,3}(<(hr)\b([^<>])*?\/?>)[ \t]*(?=\n{2,}))/g, hashElement);
|
359
|
+
|
360
|
+
// Special case for standalone HTML comments:
|
361
|
+
|
362
|
+
/*
|
363
|
+
text = text.replace(/
|
364
|
+
( // save in $1
|
365
|
+
\n\n // Starting after a blank line
|
366
|
+
[ ]{0,3} // attacklab: g_tab_width - 1
|
367
|
+
<!
|
368
|
+
(--[^\r]*?--\s*)+
|
369
|
+
>
|
370
|
+
[ \t]*
|
371
|
+
(?=\n{2,}) // followed by a blank line
|
372
|
+
)
|
373
|
+
/g,hashElement);
|
374
|
+
*/
|
375
|
+
text = text.replace(/(\n\n[ ]{0,3}<!(--[^\r]*?--\s*)+>[ \t]*(?=\n{2,}))/g, hashElement);
|
376
|
+
|
377
|
+
// PHP and ASP-style processor instructions (<?...?> and <%...%>)
|
378
|
+
|
379
|
+
/*
|
380
|
+
text = text.replace(/
|
381
|
+
(?:
|
382
|
+
\n\n // Starting after a blank line
|
383
|
+
)
|
384
|
+
( // save in $1
|
385
|
+
[ ]{0,3} // attacklab: g_tab_width - 1
|
386
|
+
(?:
|
387
|
+
<([?%]) // $2
|
388
|
+
[^\r]*?
|
389
|
+
\2>
|
390
|
+
)
|
391
|
+
[ \t]*
|
392
|
+
(?=\n{2,}) // followed by a blank line
|
393
|
+
)
|
394
|
+
/g,hashElement);
|
395
|
+
*/
|
396
|
+
text = text.replace(/(?:\n\n)([ ]{0,3}(?:<([?%])[^\r]*?\2>)[ \t]*(?=\n{2,}))/g, hashElement);
|
397
|
+
|
398
|
+
// attacklab: Undo double lines (see comment at top of this function)
|
399
|
+
text = text.replace(/\n\n/g, "\n");
|
400
|
+
return text;
|
401
|
+
};
|
402
|
+
|
403
|
+
var hashElement = function(wholeMatch, m1) {
|
404
|
+
var blockText = m1;
|
405
|
+
|
406
|
+
// Undo double lines
|
407
|
+
blockText = blockText.replace(/\n\n/g, "\n");
|
408
|
+
blockText = blockText.replace(/^\n/, "");
|
409
|
+
|
410
|
+
// strip trailing blank lines
|
411
|
+
blockText = blockText.replace(/\n+$/g, "");
|
412
|
+
|
413
|
+
// Replace the element text with a marker ("~KxK" where x is its key)
|
414
|
+
blockText = "\n\n~K" + (g_html_blocks.push(blockText) - 1) + "K\n\n";
|
415
|
+
|
416
|
+
return blockText;
|
417
|
+
};
|
418
|
+
|
419
|
+
//
|
420
|
+
// These are all the transformations that form block-level
|
421
|
+
// tags like paragraphs, headers, and list items.
|
422
|
+
//
|
423
|
+
var _RunBlockGamut = function(text) {
|
424
|
+
text = _DoHeaders(text);
|
425
|
+
|
426
|
+
// Do Horizontal Rules:
|
427
|
+
var key = hashBlock("<hr />");
|
428
|
+
text = text.replace(/^[ ]{0,2}([ ]?\*[ ]?){3,}[ \t]*$/gm, key);
|
429
|
+
text = text.replace(/^[ ]{0,2}([ ]?\-[ ]?){3,}[ \t]*$/gm, key);
|
430
|
+
text = text.replace(/^[ ]{0,2}([ ]?\_[ ]?){3,}[ \t]*$/gm, key);
|
431
|
+
|
432
|
+
text = _DoLists(text);
|
433
|
+
text = _DoCodeBlocks(text);
|
434
|
+
text = _DoBlockQuotes(text);
|
435
|
+
|
436
|
+
// We already ran _HashHTMLBlocks() before, in Markdown(), but that
|
437
|
+
// was to escape raw HTML in the original Markdown source. This time,
|
438
|
+
// we're escaping the markup we've just created, so that we don't wrap
|
439
|
+
// <p> tags around block-level tags.
|
440
|
+
text = _HashHTMLBlocks(text);
|
441
|
+
text = _FormParagraphs(text);
|
442
|
+
|
443
|
+
return text;
|
444
|
+
};
|
445
|
+
|
446
|
+
//
|
447
|
+
// These are all the transformations that occur *within* block-level
|
448
|
+
// tags like paragraphs, headers, and list items.
|
449
|
+
//
|
450
|
+
var _RunSpanGamut = function(text) {
|
451
|
+
|
452
|
+
text = _DoCodeSpans(text);
|
453
|
+
text = _EscapeSpecialCharsWithinTagAttributes(text);
|
454
|
+
text = _EncodeBackslashEscapes(text);
|
455
|
+
|
456
|
+
// Process anchor and image tags. Images must come first,
|
457
|
+
// because ![foo][f] looks like an anchor.
|
458
|
+
text = _DoImages(text);
|
459
|
+
text = _DoAnchors(text);
|
460
|
+
|
461
|
+
// Make links out of things like `<http://example.com/>`
|
462
|
+
// Must come after _DoAnchors(), because you can use < and >
|
463
|
+
// delimiters in inline links like [this](<url>).
|
464
|
+
text = _DoAutoLinks(text);
|
465
|
+
text = _EncodeAmpsAndAngles(text);
|
466
|
+
text = _DoItalicsAndBold(text);
|
467
|
+
|
468
|
+
// Do hard breaks:
|
469
|
+
text = text.replace(/ +\n/g, " <br />\n");
|
470
|
+
|
471
|
+
return text;
|
472
|
+
};
|
473
|
+
|
474
|
+
//
|
475
|
+
// Within tags -- meaning between < and > -- encode [\ ` * _] so they
|
476
|
+
// don't conflict with their use in Markdown for code, italics and strong.
|
477
|
+
//
|
478
|
+
var _EscapeSpecialCharsWithinTagAttributes = function(text) {
|
479
|
+
|
480
|
+
// Build a regex to find HTML tags and comments. See Friedl's
|
481
|
+
// "Mastering Regular Expressions", 2nd Ed., pp. 200-201.
|
482
|
+
var regex = /(<[a-z\/!$]("[^"]*"|'[^']*'|[^'">])*>|<!(--.*?--\s*)+>)/gi;
|
483
|
+
|
484
|
+
text = text.replace(regex, function(wholeMatch) {
|
485
|
+
var tag = wholeMatch.replace(/(.)<\/?code>(?=.)/g, "$1`");
|
486
|
+
tag = escapeCharacters(tag, "\\`*_");
|
487
|
+
return tag;
|
488
|
+
});
|
489
|
+
|
490
|
+
return text;
|
491
|
+
};
|
492
|
+
|
493
|
+
//
|
494
|
+
// Turn Markdown link shortcuts into XHTML <a> tags.
|
495
|
+
//
|
496
|
+
var _DoAnchors = function(text) {
|
497
|
+
//
|
498
|
+
// First, handle reference-style links: [link text] [id]
|
499
|
+
//
|
500
|
+
|
501
|
+
/*
|
502
|
+
text = text.replace(/
|
503
|
+
( // wrap whole match in $1
|
504
|
+
\[
|
505
|
+
(
|
506
|
+
(?:
|
507
|
+
\[[^\]]*\] // allow brackets nested one level
|
508
|
+
|
|
509
|
+
[^\[] // or anything else
|
510
|
+
)*
|
511
|
+
)
|
512
|
+
\]
|
513
|
+
|
514
|
+
[ ]? // one optional space
|
515
|
+
(?:\n[ ]*)? // one optional newline followed by spaces
|
516
|
+
|
517
|
+
\[
|
518
|
+
(.*?) // id = $3
|
519
|
+
\]
|
520
|
+
)()()()() // pad remaining backreferences
|
521
|
+
/g,_DoAnchors_callback);
|
522
|
+
*/
|
523
|
+
text = text.replace(/(\[((?:\[[^\]]*\]|[^\[\]])*)\][ ]?(?:\n[ ]*)?\[(.*?)\])()()()()/g, writeAnchorTag);
|
524
|
+
|
525
|
+
//
|
526
|
+
// Next, inline-style links: [link text](url "optional title")
|
527
|
+
//
|
528
|
+
|
529
|
+
/*
|
530
|
+
text = text.replace(/
|
531
|
+
( // wrap whole match in $1
|
532
|
+
\[
|
533
|
+
(
|
534
|
+
(?:
|
535
|
+
\[[^\]]*\] // allow brackets nested one level
|
536
|
+
|
|
537
|
+
[^\[\]] // or anything else
|
538
|
+
)
|
539
|
+
)
|
540
|
+
\]
|
541
|
+
\( // literal paren
|
542
|
+
[ \t]*
|
543
|
+
() // no id, so leave $3 empty
|
544
|
+
<?(.*?)>? // href = $4
|
545
|
+
[ \t]*
|
546
|
+
( // $5
|
547
|
+
(['"]) // quote char = $6
|
548
|
+
(.*?) // Title = $7
|
549
|
+
\6 // matching quote
|
550
|
+
[ \t]* // ignore any spaces/tabs between closing quote and )
|
551
|
+
)? // title is optional
|
552
|
+
\)
|
553
|
+
)
|
554
|
+
/g,writeAnchorTag);
|
555
|
+
*/
|
556
|
+
text = text.replace(/(\[((?:\[[^\]]*\]|[^\[\]])*)\]\([ \t]*()<?(.*?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g, writeAnchorTag);
|
557
|
+
|
558
|
+
//
|
559
|
+
// Last, handle reference-style shortcuts: [link text]
|
560
|
+
// These must come last in case you've also got [link test][1]
|
561
|
+
// or [link test](/foo)
|
562
|
+
//
|
563
|
+
|
564
|
+
/*
|
565
|
+
text = text.replace(/
|
566
|
+
( // wrap whole match in $1
|
567
|
+
\[
|
568
|
+
([^\[\]]+) // link text = $2; can't contain '[' or ']'
|
569
|
+
\]
|
570
|
+
)()()()()() // pad rest of backreferences
|
571
|
+
/g, writeAnchorTag);
|
572
|
+
*/
|
573
|
+
text = text.replace(/(\[([^\[\]]+)\])()()()()()/g, writeAnchorTag);
|
574
|
+
|
575
|
+
return text;
|
576
|
+
};
|
577
|
+
|
578
|
+
var writeAnchorTag = function(wholeMatch, m1, m2, m3, m4, m5, m6, m7) {
|
579
|
+
if (m7 == undefined) m7 = "";
|
580
|
+
var whole_match = m1;
|
581
|
+
var link_text = m2;
|
582
|
+
var link_id = m3.toLowerCase();
|
583
|
+
var url = m4;
|
584
|
+
var title = m7;
|
585
|
+
|
586
|
+
if (url == "") {
|
587
|
+
if (link_id == "") {
|
588
|
+
// lower-case and turn embedded newlines into spaces
|
589
|
+
link_id = link_text.toLowerCase().replace(/ ?\n/g, " ");
|
590
|
+
}
|
591
|
+
url = "#" + link_id;
|
592
|
+
|
593
|
+
if (g_urls[link_id] != undefined) {
|
594
|
+
url = g_urls[link_id];
|
595
|
+
if (g_titles[link_id] != undefined) {
|
596
|
+
title = g_titles[link_id];
|
597
|
+
}
|
598
|
+
}
|
599
|
+
else {
|
600
|
+
if (whole_match.search(/\(\s*\)$/m) > -1) {
|
601
|
+
// Special case for explicit empty url
|
602
|
+
url = "";
|
603
|
+
} else {
|
604
|
+
return whole_match;
|
605
|
+
}
|
606
|
+
}
|
607
|
+
}
|
608
|
+
|
609
|
+
url = escapeCharacters(url, "*_");
|
610
|
+
var result = "<a href=\"" + url + "\"";
|
611
|
+
|
612
|
+
if (title != "") {
|
613
|
+
title = title.replace(/"/g, """);
|
614
|
+
title = escapeCharacters(title, "*_");
|
615
|
+
result += " title=\"" + title + "\"";
|
616
|
+
}
|
617
|
+
|
618
|
+
result += ">" + link_text + "</a>";
|
619
|
+
|
620
|
+
return result;
|
621
|
+
};
|
622
|
+
|
623
|
+
|
624
|
+
//
|
625
|
+
// Turn Markdown image shortcuts into <img> tags.
|
626
|
+
//
|
627
|
+
var _DoImages = function(text) {
|
628
|
+
//
|
629
|
+
// First, handle reference-style labeled images: ![alt text][id]
|
630
|
+
//
|
631
|
+
|
632
|
+
/*
|
633
|
+
text = text.replace(/
|
634
|
+
( // wrap whole match in $1
|
635
|
+
!\[
|
636
|
+
(.*?) // alt text = $2
|
637
|
+
\]
|
638
|
+
|
639
|
+
[ ]? // one optional space
|
640
|
+
(?:\n[ ]*)? // one optional newline followed by spaces
|
641
|
+
|
642
|
+
\[
|
643
|
+
(.*?) // id = $3
|
644
|
+
\]
|
645
|
+
)()()()() // pad rest of backreferences
|
646
|
+
/g,writeImageTag);
|
647
|
+
*/
|
648
|
+
text = text.replace(/(!\[(.*?)\][ ]?(?:\n[ ]*)?\[(.*?)\])()()()()/g, writeImageTag);
|
649
|
+
|
650
|
+
//
|
651
|
+
// Next, handle inline images: 
|
652
|
+
// Don't forget: encode * and _
|
653
|
+
|
654
|
+
/*
|
655
|
+
text = text.replace(/
|
656
|
+
( // wrap whole match in $1
|
657
|
+
!\[
|
658
|
+
(.*?) // alt text = $2
|
659
|
+
\]
|
660
|
+
\s? // One optional whitespace character
|
661
|
+
\( // literal paren
|
662
|
+
[ \t]*
|
663
|
+
() // no id, so leave $3 empty
|
664
|
+
<?(\S+?)>? // src url = $4
|
665
|
+
[ \t]*
|
666
|
+
( // $5
|
667
|
+
(['"]) // quote char = $6
|
668
|
+
(.*?) // title = $7
|
669
|
+
\6 // matching quote
|
670
|
+
[ \t]*
|
671
|
+
)? // title is optional
|
672
|
+
\)
|
673
|
+
)
|
674
|
+
/g,writeImageTag);
|
675
|
+
*/
|
676
|
+
text = text.replace(/(!\[(.*?)\]\s?\([ \t]*()<?(\S+?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g, writeImageTag);
|
677
|
+
|
678
|
+
return text;
|
679
|
+
};
|
680
|
+
|
681
|
+
var writeImageTag = function(wholeMatch, m1, m2, m3, m4, m5, m6, m7) {
|
682
|
+
var whole_match = m1;
|
683
|
+
var alt_text = m2;
|
684
|
+
var link_id = m3.toLowerCase();
|
685
|
+
var url = m4;
|
686
|
+
var title = m7;
|
687
|
+
|
688
|
+
if (!title) title = "";
|
689
|
+
|
690
|
+
if (url == "") {
|
691
|
+
if (link_id == "") {
|
692
|
+
// lower-case and turn embedded newlines into spaces
|
693
|
+
link_id = alt_text.toLowerCase().replace(/ ?\n/g, " ");
|
694
|
+
}
|
695
|
+
url = "#" + link_id;
|
696
|
+
|
697
|
+
if (g_urls[link_id] != undefined) {
|
698
|
+
url = g_urls[link_id];
|
699
|
+
if (g_titles[link_id] != undefined) {
|
700
|
+
title = g_titles[link_id];
|
701
|
+
}
|
702
|
+
}
|
703
|
+
else {
|
704
|
+
return whole_match;
|
705
|
+
}
|
706
|
+
}
|
707
|
+
|
708
|
+
alt_text = alt_text.replace(/"/g, """);
|
709
|
+
url = escapeCharacters(url, "*_");
|
710
|
+
var result = "<img src=\"" + url + "\" alt=\"" + alt_text + "\"";
|
711
|
+
|
712
|
+
// attacklab: Markdown.pl adds empty title attributes to images.
|
713
|
+
// Replicate this bug.
|
714
|
+
|
715
|
+
//if (title != "") {
|
716
|
+
title = title.replace(/"/g, """);
|
717
|
+
title = escapeCharacters(title, "*_");
|
718
|
+
result += " title=\"" + title + "\"";
|
719
|
+
//}
|
720
|
+
|
721
|
+
result += " />";
|
722
|
+
|
723
|
+
return result;
|
724
|
+
};
|
725
|
+
|
726
|
+
|
727
|
+
var _DoHeaders = function(text) {
|
728
|
+
|
729
|
+
// Setext-style headers:
|
730
|
+
// Header 1
|
731
|
+
// ========
|
732
|
+
//
|
733
|
+
// Header 2
|
734
|
+
// --------
|
735
|
+
//
|
736
|
+
text = text.replace(/^(.+)[ \t]*\n=+[ \t]*\n+/gm,
|
737
|
+
function(wholeMatch, m1) {
|
738
|
+
return hashBlock("<h1>" + _RunSpanGamut(m1) + "</h1>");
|
739
|
+
});
|
740
|
+
|
741
|
+
text = text.replace(/^(.+)[ \t]*\n-+[ \t]*\n+/gm,
|
742
|
+
function(matchFound, m1) {
|
743
|
+
return hashBlock("<h2>" + _RunSpanGamut(m1) + "</h2>");
|
744
|
+
});
|
745
|
+
|
746
|
+
// atx-style headers:
|
747
|
+
// # Header 1
|
748
|
+
// ## Header 2
|
749
|
+
// ## Header 2 with closing hashes ##
|
750
|
+
// ...
|
751
|
+
// ###### Header 6
|
752
|
+
//
|
753
|
+
|
754
|
+
/*
|
755
|
+
text = text.replace(/
|
756
|
+
^(\#{1,6}) // $1 = string of #'s
|
757
|
+
[ \t]*
|
758
|
+
(.+?) // $2 = Header text
|
759
|
+
[ \t]*
|
760
|
+
\#* // optional closing #'s (not counted)
|
761
|
+
\n+
|
762
|
+
/gm, function() {...});
|
763
|
+
*/
|
764
|
+
|
765
|
+
text = text.replace(/^(\#{1,6})[ \t]*(.+?)[ \t]*\#*\n+/gm,
|
766
|
+
function(wholeMatch, m1, m2) {
|
767
|
+
var h_level = m1.length;
|
768
|
+
return hashBlock("<h" + h_level + ">" + _RunSpanGamut(m2) + "</h" + h_level + ">");
|
769
|
+
});
|
770
|
+
|
771
|
+
return text;
|
772
|
+
};
|
773
|
+
|
774
|
+
// This declaration keeps Dojo compressor from outputting garbage:
|
775
|
+
var _ProcessListItems;
|
776
|
+
|
777
|
+
//
|
778
|
+
// Form HTML ordered (numbered) and unordered (bulleted) lists.
|
779
|
+
//
|
780
|
+
var _DoLists = function(text) {
|
781
|
+
|
782
|
+
// attacklab: add sentinel to hack around khtml/safari bug:
|
783
|
+
// http://bugs.webkit.org/show_bug.cgi?id=11231
|
784
|
+
text += "~0";
|
785
|
+
|
786
|
+
// Re-usable pattern to match any entirel ul or ol list:
|
787
|
+
|
788
|
+
/*
|
789
|
+
var whole_list = /
|
790
|
+
( // $1 = whole list
|
791
|
+
( // $2
|
792
|
+
[ ]{0,3} // attacklab: g_tab_width - 1
|
793
|
+
([*+-]|\d+[.]) // $3 = first list item marker
|
794
|
+
[ \t]+
|
795
|
+
)
|
796
|
+
[^\r]+?
|
797
|
+
( // $4
|
798
|
+
~0 // sentinel for workaround; should be $
|
799
|
+
|
|
800
|
+
\n{2,}
|
801
|
+
(?=\S)
|
802
|
+
(?! // Negative lookahead for another list item marker
|
803
|
+
[ \t]*
|
804
|
+
(?:[*+-]|\d+[.])[ \t]+
|
805
|
+
)
|
806
|
+
)
|
807
|
+
)/g
|
808
|
+
*/
|
809
|
+
var whole_list = /^(([ ]{0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(~0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm;
|
810
|
+
|
811
|
+
if (g_list_level) {
|
812
|
+
text = text.replace(whole_list, function(wholeMatch, m1, m2) {
|
813
|
+
var list = m1;
|
814
|
+
var list_type = (m2.search(/[*+-]/g) > -1) ? "ul" : "ol";
|
815
|
+
|
816
|
+
// Turn double returns into triple returns, so that we can make a
|
817
|
+
// paragraph for the last item in a list, if necessary:
|
818
|
+
list = list.replace(/\n{2,}/g, "\n\n\n");
|
819
|
+
var result = _ProcessListItems(list);
|
820
|
+
|
821
|
+
// Trim any trailing whitespace, to put the closing `</$list_type>`
|
822
|
+
// up on the preceding line, to get it past the current stupid
|
823
|
+
// HTML block parser. This is a hack to work around the terrible
|
824
|
+
// hack that is the HTML block parser.
|
825
|
+
result = result.replace(/\s+$/, "");
|
826
|
+
result = "<" + list_type + ">" + result + "</" + list_type + ">\n";
|
827
|
+
return result;
|
828
|
+
});
|
829
|
+
} else {
|
830
|
+
whole_list = /(\n\n|^\n?)(([ ]{0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(~0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/g;
|
831
|
+
text = text.replace(whole_list, function(wholeMatch, m1, m2, m3) {
|
832
|
+
var runup = m1;
|
833
|
+
var list = m2;
|
834
|
+
|
835
|
+
var list_type = (m3.search(/[*+-]/g) > -1) ? "ul" : "ol";
|
836
|
+
// Turn double returns into triple returns, so that we can make a
|
837
|
+
// paragraph for the last item in a list, if necessary:
|
838
|
+
var list = list.replace(/\n{2,}/g, "\n\n\n");
|
839
|
+
var result = _ProcessListItems(list);
|
840
|
+
result = runup + "<" + list_type + ">\n" + result + "</" + list_type + ">\n";
|
841
|
+
return result;
|
842
|
+
});
|
843
|
+
}
|
844
|
+
|
845
|
+
// attacklab: strip sentinel
|
846
|
+
text = text.replace(/~0/, "");
|
847
|
+
|
848
|
+
return text;
|
849
|
+
};
|
850
|
+
|
851
|
+
//
|
852
|
+
// Process the contents of a single ordered or unordered list, splitting it
|
853
|
+
// into individual list items.
|
854
|
+
//
|
855
|
+
_ProcessListItems = function(list_str) {
|
856
|
+
// The $g_list_level global keeps track of when we're inside a list.
|
857
|
+
// Each time we enter a list, we increment it; when we leave a list,
|
858
|
+
// we decrement. If it's zero, we're not in a list anymore.
|
859
|
+
//
|
860
|
+
// We do this because when we're not inside a list, we want to treat
|
861
|
+
// something like this:
|
862
|
+
//
|
863
|
+
// I recommend upgrading to version
|
864
|
+
// 8. Oops, now this line is treated
|
865
|
+
// as a sub-list.
|
866
|
+
//
|
867
|
+
// As a single paragraph, despite the fact that the second line starts
|
868
|
+
// with a digit-period-space sequence.
|
869
|
+
//
|
870
|
+
// Whereas when we're inside a list (or sub-list), that line will be
|
871
|
+
// treated as the start of a sub-list. What a kludge, huh? This is
|
872
|
+
// an aspect of Markdown's syntax that's hard to parse perfectly
|
873
|
+
// without resorting to mind-reading. Perhaps the solution is to
|
874
|
+
// change the syntax rules such that sub-lists must start with a
|
875
|
+
// starting cardinal number; e.g. "1." or "a.".
|
876
|
+
|
877
|
+
g_list_level++;
|
878
|
+
|
879
|
+
// trim trailing blank lines:
|
880
|
+
list_str = list_str.replace(/\n{2,}$/, "\n");
|
881
|
+
|
882
|
+
// attacklab: add sentinel to emulate \z
|
883
|
+
list_str += "~0";
|
884
|
+
|
885
|
+
/*
|
886
|
+
list_str = list_str.replace(/
|
887
|
+
(\n)? // leading line = $1
|
888
|
+
(^[ \t]*) // leading whitespace = $2
|
889
|
+
([*+-]|\d+[.]) [ \t]+ // list marker = $3
|
890
|
+
([^\r]+? // list item text = $4
|
891
|
+
(\n{1,2}))
|
892
|
+
(?= \n* (~0 | \2 ([*+-]|\d+[.]) [ \t]+))
|
893
|
+
/gm, function(){...});
|
894
|
+
*/
|
895
|
+
list_str = list_str.replace(/(\n)?(^[ \t]*)([*+-]|\d+[.])[ \t]+([^\r]+?(\n{1,2}))(?=\n*(~0|\2([*+-]|\d+[.])[ \t]+))/gm,
|
896
|
+
function(wholeMatch, m1, m2, m3, m4) {
|
897
|
+
var item = m4;
|
898
|
+
var leading_line = m1;
|
899
|
+
var leading_space = m2;
|
900
|
+
|
901
|
+
if (leading_line || (item.search(/\n{2,}/) > -1)) {
|
902
|
+
item = _RunBlockGamut(_Outdent(item));
|
903
|
+
}
|
904
|
+
else {
|
905
|
+
// Recursion for sub-lists:
|
906
|
+
item = _DoLists(_Outdent(item));
|
907
|
+
item = item.replace(/\n$/, ""); // chomp(item)
|
908
|
+
item = _RunSpanGamut(item);
|
909
|
+
}
|
910
|
+
|
911
|
+
return "<li>" + item + "</li>\n";
|
912
|
+
}
|
913
|
+
);
|
914
|
+
|
915
|
+
// attacklab: strip sentinel
|
916
|
+
list_str = list_str.replace(/~0/g, "");
|
917
|
+
|
918
|
+
g_list_level--;
|
919
|
+
return list_str;
|
920
|
+
};
|
921
|
+
|
922
|
+
|
923
|
+
//
|
924
|
+
// Process Markdown `<pre><code>` blocks.
|
925
|
+
//
|
926
|
+
var _DoCodeBlocks = function(text) {
|
927
|
+
|
928
|
+
/*
|
929
|
+
text = text.replace(text,
|
930
|
+
/(?:\n\n|^)
|
931
|
+
( // $1 = the code block -- one or more lines, starting with a space/tab
|
932
|
+
(?:
|
933
|
+
(?:[ ]{4}|\t) // Lines must start with a tab or a tab-width of spaces - attacklab: g_tab_width
|
934
|
+
.*\n+
|
935
|
+
)+
|
936
|
+
)
|
937
|
+
(\n*[ ]{0,3}[^ \t\n]|(?=~0)) // attacklab: g_tab_width
|
938
|
+
/g,function(){...});
|
939
|
+
*/
|
940
|
+
|
941
|
+
// attacklab: sentinel workarounds for lack of \A and \Z, safari\khtml bug
|
942
|
+
text += "~0";
|
943
|
+
|
944
|
+
text = text.replace(/(?:\n\n|^)((?:(?:[ ]{4}|\t).*\n+)+)(\n*[ ]{0,3}[^ \t\n]|(?=~0))/g, function(wholeMatch, m1, m2) {
|
945
|
+
var codeblock = m1;
|
946
|
+
var nextChar = m2;
|
947
|
+
|
948
|
+
codeblock = _EncodeCode(_Outdent(codeblock));
|
949
|
+
codeblock = _Detab(codeblock);
|
950
|
+
codeblock = codeblock.replace(/^\n+/g, ""); // trim leading newlines
|
951
|
+
codeblock = codeblock.replace(/\n+$/g, ""); // trim trailing whitespace
|
952
|
+
|
953
|
+
codeblock = "<pre><code>" + codeblock + "\n</code></pre>";
|
954
|
+
|
955
|
+
return hashBlock(codeblock) + nextChar;
|
956
|
+
});
|
957
|
+
|
958
|
+
// attacklab: strip sentinel
|
959
|
+
text = text.replace(/~0/, "");
|
960
|
+
|
961
|
+
return text;
|
962
|
+
};
|
963
|
+
|
964
|
+
var hashBlock = function(text) {
|
965
|
+
text = text.replace(/(^\n+|\n+$)/g, "");
|
966
|
+
return "\n\n~K" + (g_html_blocks.push(text) - 1) + "K\n\n";
|
967
|
+
};
|
968
|
+
|
969
|
+
|
970
|
+
//
|
971
|
+
// * Backtick quotes are used for <code></code> spans.
|
972
|
+
//
|
973
|
+
// * You can use multiple backticks as the delimiters if you want to
|
974
|
+
// include literal backticks in the code span. So, this input:
|
975
|
+
//
|
976
|
+
// Just type ``foo `bar` baz`` at the prompt.
|
977
|
+
//
|
978
|
+
// Will translate to:
|
979
|
+
//
|
980
|
+
// <p>Just type <code>foo `bar` baz</code> at the prompt.</p>
|
981
|
+
//
|
982
|
+
// There's no arbitrary limit to the number of backticks you
|
983
|
+
// can use as delimters. If you need three consecutive backticks
|
984
|
+
// in your code, use four for delimiters, etc.
|
985
|
+
//
|
986
|
+
// * You can use spaces to get literal backticks at the edges:
|
987
|
+
//
|
988
|
+
// ... type `` `bar` `` ...
|
989
|
+
//
|
990
|
+
// Turns to:
|
991
|
+
//
|
992
|
+
// ... type <code>`bar`</code> ...
|
993
|
+
//
|
994
|
+
var _DoCodeSpans = function(text) {
|
995
|
+
/*
|
996
|
+
text = text.replace(/
|
997
|
+
(^|[^\\]) // Character before opening ` can't be a backslash
|
998
|
+
(`+) // $2 = Opening run of `
|
999
|
+
( // $3 = The code block
|
1000
|
+
[^\r]*?
|
1001
|
+
[^`] // attacklab: work around lack of lookbehind
|
1002
|
+
)
|
1003
|
+
\2 // Matching closer
|
1004
|
+
(?!`)
|
1005
|
+
/gm, function(){...});
|
1006
|
+
*/
|
1007
|
+
|
1008
|
+
text = text.replace(/(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm,
|
1009
|
+
function(wholeMatch, m1, m2, m3, m4) {
|
1010
|
+
var c = m3;
|
1011
|
+
c = c.replace(/^([ \t]*)/g, ""); // leading whitespace
|
1012
|
+
c = c.replace(/[ \t]*$/g, ""); // trailing whitespace
|
1013
|
+
c = _EncodeCode(c);
|
1014
|
+
return m1 + "<code>" + c + "</code>";
|
1015
|
+
});
|
1016
|
+
|
1017
|
+
return text;
|
1018
|
+
};
|
1019
|
+
|
1020
|
+
|
1021
|
+
//
|
1022
|
+
// Encode/escape certain characters inside Markdown code runs.
|
1023
|
+
// The point is that in code, these characters are literals,
|
1024
|
+
// and lose their special Markdown meanings.
|
1025
|
+
//
|
1026
|
+
var _EncodeCode = function(text) {
|
1027
|
+
// Encode all ampersands; HTML entities are not
|
1028
|
+
// entities within a Markdown code span.
|
1029
|
+
text = text.replace(/&/g, "&");
|
1030
|
+
|
1031
|
+
// Do the angle bracket song and dance:
|
1032
|
+
text = text.replace(/</g, "<");
|
1033
|
+
text = text.replace(/>/g, ">");
|
1034
|
+
|
1035
|
+
// Now, escape characters that are magic in Markdown:
|
1036
|
+
text = escapeCharacters(text, "\*_{}[]\\", false);
|
1037
|
+
|
1038
|
+
return text;
|
1039
|
+
};
|
1040
|
+
|
1041
|
+
|
1042
|
+
var _DoItalicsAndBold = function(text) {
|
1043
|
+
|
1044
|
+
// <strong> must go first:
|
1045
|
+
text = text.replace(/(\*\*|__)(?=\S)([^\r]*?\S[*_]*)\1/g,
|
1046
|
+
"<strong>$2</strong>");
|
1047
|
+
|
1048
|
+
text = text.replace(/(\w)_(\w)/g, "$1~E95E$2"); // ** GFM ** "~E95E" == escaped "_"
|
1049
|
+
text = text.replace(/(\*|_)(?=\S)([^\r]*?\S)\1/g,
|
1050
|
+
"<em>$2</em>");
|
1051
|
+
|
1052
|
+
return text;
|
1053
|
+
};
|
1054
|
+
|
1055
|
+
|
1056
|
+
var _DoBlockQuotes = function(text) {
|
1057
|
+
|
1058
|
+
/*
|
1059
|
+
text = text.replace(/
|
1060
|
+
( // Wrap whole match in $1
|
1061
|
+
(
|
1062
|
+
^[ \t]*>[ \t]? // '>' at the start of a line
|
1063
|
+
.+\n // rest of the first line
|
1064
|
+
(.+\n)* // subsequent consecutive lines
|
1065
|
+
\n* // blanks
|
1066
|
+
)+
|
1067
|
+
)
|
1068
|
+
/gm, function(){...});
|
1069
|
+
*/
|
1070
|
+
|
1071
|
+
text = text.replace(/((^[ \t]*>[ \t]?.+\n(.+\n)*\n*)+)/gm,
|
1072
|
+
function(wholeMatch, m1) {
|
1073
|
+
var bq = m1;
|
1074
|
+
|
1075
|
+
// attacklab: hack around Konqueror 3.5.4 bug:
|
1076
|
+
// "----------bug".replace(/^-/g,"") == "bug"
|
1077
|
+
|
1078
|
+
bq = bq.replace(/^[ \t]*>[ \t]?/gm, "~0"); // trim one level of quoting
|
1079
|
+
|
1080
|
+
// attacklab: clean up hack
|
1081
|
+
bq = bq.replace(/~0/g, "");
|
1082
|
+
|
1083
|
+
bq = bq.replace(/^[ \t]+$/gm, ""); // trim whitespace-only lines
|
1084
|
+
bq = _RunBlockGamut(bq); // recurse
|
1085
|
+
|
1086
|
+
bq = bq.replace(/(^|\n)/g, "$1 ");
|
1087
|
+
// These leading spaces screw with <pre> content, so we need to fix that:
|
1088
|
+
bq = bq.replace(
|
1089
|
+
/(\s*<pre>[^\r]+?<\/pre>)/gm,
|
1090
|
+
function(wholeMatch, m1) {
|
1091
|
+
var pre = m1;
|
1092
|
+
// attacklab: hack around Konqueror 3.5.4 bug:
|
1093
|
+
pre = pre.replace(/^ /mg, "~0");
|
1094
|
+
pre = pre.replace(/~0/g, "");
|
1095
|
+
return pre;
|
1096
|
+
});
|
1097
|
+
|
1098
|
+
return hashBlock("<blockquote>\n" + bq + "\n</blockquote>");
|
1099
|
+
});
|
1100
|
+
return text;
|
1101
|
+
};
|
1102
|
+
|
1103
|
+
|
1104
|
+
//
|
1105
|
+
// Params:
|
1106
|
+
// $text - string to process with html <p> tags
|
1107
|
+
//
|
1108
|
+
var _FormParagraphs = function(text) {
|
1109
|
+
|
1110
|
+
// Strip leading and trailing lines:
|
1111
|
+
text = text.replace(/^\n+/g, "");
|
1112
|
+
text = text.replace(/\n+$/g, "");
|
1113
|
+
|
1114
|
+
var grafs = text.split(/\n{2,}/g);
|
1115
|
+
var grafsOut = new Array();
|
1116
|
+
|
1117
|
+
//
|
1118
|
+
// Wrap <p> tags.
|
1119
|
+
//
|
1120
|
+
var end = grafs.length;
|
1121
|
+
for (var i = 0; i < end; i++) {
|
1122
|
+
var str = grafs[i];
|
1123
|
+
|
1124
|
+
// if this is an HTML marker, copy it
|
1125
|
+
if (str.search(/~K(\d+)K/g) >= 0) {
|
1126
|
+
grafsOut.push(str);
|
1127
|
+
}
|
1128
|
+
else if (str.search(/\S/) >= 0) {
|
1129
|
+
str = _RunSpanGamut(str);
|
1130
|
+
str = str.replace(/\n/g, "<br />"); // ** GFM **
|
1131
|
+
str = str.replace(/^([ \t]*)/g, "<p>");
|
1132
|
+
str += "</p>";
|
1133
|
+
grafsOut.push(str);
|
1134
|
+
}
|
1135
|
+
|
1136
|
+
}
|
1137
|
+
|
1138
|
+
//
|
1139
|
+
// Unhashify HTML blocks
|
1140
|
+
//
|
1141
|
+
end = grafsOut.length;
|
1142
|
+
for (var i = 0; i < end; i++) {
|
1143
|
+
// if this is a marker for an html block...
|
1144
|
+
while (grafsOut[i].search(/~K(\d+)K/) >= 0) {
|
1145
|
+
var blockText = g_html_blocks[RegExp.$1];
|
1146
|
+
blockText = blockText.replace(/\$/g, "$$$$"); // Escape any dollar signs
|
1147
|
+
grafsOut[i] = grafsOut[i].replace(/~K\d+K/, blockText);
|
1148
|
+
}
|
1149
|
+
}
|
1150
|
+
|
1151
|
+
return grafsOut.join("\n\n");
|
1152
|
+
};
|
1153
|
+
|
1154
|
+
// Smart processing for ampersands and angle brackets that need to be encoded.
|
1155
|
+
var _EncodeAmpsAndAngles = function(text) {
|
1156
|
+
|
1157
|
+
// Ampersand-encoding based entirely on Nat Irons's Amputator MT plugin:
|
1158
|
+
// http://bumppo.net/projects/amputator/
|
1159
|
+
text = text.replace(/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/g, "&");
|
1160
|
+
|
1161
|
+
// Encode naked <'s
|
1162
|
+
text = text.replace(/<(?![a-z\/?\$!])/gi, "<");
|
1163
|
+
|
1164
|
+
return text;
|
1165
|
+
};
|
1166
|
+
|
1167
|
+
//
|
1168
|
+
// Parameter: String.
|
1169
|
+
// Returns: The string, with after processing the following backslash
|
1170
|
+
// escape sequences.
|
1171
|
+
//
|
1172
|
+
var _EncodeBackslashEscapes = function(text) {
|
1173
|
+
// attacklab: The polite way to do this is with the new
|
1174
|
+
// escapeCharacters() function:
|
1175
|
+
//
|
1176
|
+
// text = escapeCharacters(text,"\\",true);
|
1177
|
+
// text = escapeCharacters(text,"`*_{}[]()>#+-.!",true);
|
1178
|
+
//
|
1179
|
+
// ...but we're sidestepping its use of the (slow) RegExp constructor
|
1180
|
+
// as an optimization for Firefox. This function gets called a LOT.
|
1181
|
+
|
1182
|
+
text = text.replace(/\\(\\)/g, escapeCharacters_callback);
|
1183
|
+
text = text.replace(/\\([`*_{}\[\]()>#+-.!])/g, escapeCharacters_callback);
|
1184
|
+
return text;
|
1185
|
+
};
|
1186
|
+
|
1187
|
+
var _DoAutoLinks = function(text) {
|
1188
|
+
|
1189
|
+
text = text.replace(/<((https?|ftp|dict):[^'">\s]+)>/gi, "<a href=\"$1\">$1</a>");
|
1190
|
+
|
1191
|
+
// Email addresses: <address@domain.foo>
|
1192
|
+
|
1193
|
+
/*
|
1194
|
+
text = text.replace(/
|
1195
|
+
<
|
1196
|
+
(?:mailto:)?
|
1197
|
+
(
|
1198
|
+
[-.\w]+
|
1199
|
+
\@
|
1200
|
+
[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+
|
1201
|
+
)
|
1202
|
+
>
|
1203
|
+
/gi, _DoAutoLinks_callback());
|
1204
|
+
*/
|
1205
|
+
text = text.replace(/<(?:mailto:)?([-.\w]+\@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi, function(wholeMatch, m1) {
|
1206
|
+
return _EncodeEmailAddress(_UnescapeSpecialChars(m1));
|
1207
|
+
});
|
1208
|
+
|
1209
|
+
return text;
|
1210
|
+
};
|
1211
|
+
|
1212
|
+
//
|
1213
|
+
// Input: an email address, e.g. "foo@example.com"
|
1214
|
+
//
|
1215
|
+
// Output: the email address as a mailto link, with each character
|
1216
|
+
// of the address encoded as either a decimal or hex entity, in
|
1217
|
+
// the hopes of foiling most address harvesting spam bots. E.g.:
|
1218
|
+
//
|
1219
|
+
// <a href="mailto:foo@e
|
1220
|
+
// xample.com">foo
|
1221
|
+
// @example.com</a>
|
1222
|
+
//
|
1223
|
+
// Based on a filter by Matthew Wickline, posted to the BBEdit-Talk
|
1224
|
+
// mailing list: <http://tinyurl.com/yu7ue>
|
1225
|
+
//
|
1226
|
+
var _EncodeEmailAddress = function(addr) {
|
1227
|
+
|
1228
|
+
// attacklab: why can't javascript speak hex?
|
1229
|
+
function char2hex(ch) {
|
1230
|
+
var hexDigits = '0123456789ABCDEF';
|
1231
|
+
var dec = ch.charCodeAt(0);
|
1232
|
+
return(hexDigits.charAt(dec >> 4) + hexDigits.charAt(dec & 15));
|
1233
|
+
}
|
1234
|
+
|
1235
|
+
var encode = [
|
1236
|
+
function(ch) { return "&#" + ch.charCodeAt(0) + ";" },
|
1237
|
+
function(ch) { return "&#x" + char2hex(ch) + ";" },
|
1238
|
+
function(ch) { return ch }
|
1239
|
+
];
|
1240
|
+
|
1241
|
+
addr = "mailto:" + addr;
|
1242
|
+
|
1243
|
+
addr = addr.replace(/./g, function(ch) {
|
1244
|
+
if (ch == "@") {
|
1245
|
+
// this *must* be encoded. I insist.
|
1246
|
+
ch = encode[Math.floor(Math.random() * 2)](ch);
|
1247
|
+
} else if (ch != ":") {
|
1248
|
+
// leave ':' alone (to spot mailto: later)
|
1249
|
+
var r = Math.random();
|
1250
|
+
// roughly 10% raw, 45% hex, 45% dec
|
1251
|
+
ch = (r > .9 ? encode[2](ch) : r > .45 ? encode[1](ch) : encode[0](ch));
|
1252
|
+
}
|
1253
|
+
return ch;
|
1254
|
+
});
|
1255
|
+
|
1256
|
+
addr = "<a href=\"" + addr + "\">" + addr + "</a>";
|
1257
|
+
addr = addr.replace(/">.+:/g, "\">"); // strip the mailto: from the visible part
|
1258
|
+
|
1259
|
+
return addr;
|
1260
|
+
};
|
1261
|
+
|
1262
|
+
//
|
1263
|
+
// Swap back in all the special characters we've hidden.
|
1264
|
+
//
|
1265
|
+
var _UnescapeSpecialChars = function(text) {
|
1266
|
+
text = text.replace(/~E(\d+)E/g, function(wholeMatch, m1) {
|
1267
|
+
var charCodeToReplace = parseInt(m1);
|
1268
|
+
return String.fromCharCode(charCodeToReplace);
|
1269
|
+
});
|
1270
|
+
return text;
|
1271
|
+
};
|
1272
|
+
|
1273
|
+
//
|
1274
|
+
// Remove one level of line-leading tabs or spaces
|
1275
|
+
//
|
1276
|
+
var _Outdent = function(text) {
|
1277
|
+
|
1278
|
+
// attacklab: hack around Konqueror 3.5.4 bug:
|
1279
|
+
// "----------bug".replace(/^-/g,"") == "bug"
|
1280
|
+
|
1281
|
+
text = text.replace(/^(\t|[ ]{1,4})/gm, "~0"); // attacklab: g_tab_width
|
1282
|
+
|
1283
|
+
// attacklab: clean up hack
|
1284
|
+
text = text.replace(/~0/g, "");
|
1285
|
+
|
1286
|
+
return text;
|
1287
|
+
};
|
1288
|
+
|
1289
|
+
// attacklab: Detab's completely rewritten for speed.
|
1290
|
+
// In perl we could fix it by anchoring the regexp with \G.
|
1291
|
+
// In javascript we're less fortunate.
|
1292
|
+
var _Detab = function(text) {
|
1293
|
+
// expand first n-1 tabs
|
1294
|
+
text = text.replace(/\t(?=\t)/g, " "); // attacklab: g_tab_width
|
1295
|
+
|
1296
|
+
// replace the nth with two sentinels
|
1297
|
+
text = text.replace(/\t/g, "~A~B");
|
1298
|
+
|
1299
|
+
// use the sentinel to anchor our regex so it doesn't explode
|
1300
|
+
text = text.replace(/~B(.+?)~A/g, function(wholeMatch, m1, m2) {
|
1301
|
+
var leadingText = m1;
|
1302
|
+
var numSpaces = 4 - leadingText.length % 4; // attacklab: g_tab_width
|
1303
|
+
|
1304
|
+
// there *must* be a better way to do this:
|
1305
|
+
for (var i = 0; i < numSpaces; i++) leadingText += " ";
|
1306
|
+
|
1307
|
+
return leadingText;
|
1308
|
+
});
|
1309
|
+
|
1310
|
+
// clean up sentinels
|
1311
|
+
text = text.replace(/~A/g, " "); // attacklab: g_tab_width
|
1312
|
+
text = text.replace(/~B/g, "");
|
1313
|
+
|
1314
|
+
return text;
|
1315
|
+
};
|
1316
|
+
|
1317
|
+
|
1318
|
+
// attacklab: Utility functions
|
1319
|
+
var escapeCharacters = function(text, charsToEscape, afterBackslash) {
|
1320
|
+
// First we have to escape the escape characters so that
|
1321
|
+
// we can build a character class out of them
|
1322
|
+
var regexString = "([" + charsToEscape.replace(/([\[\]\\])/g, "\\$1") + "])";
|
1323
|
+
|
1324
|
+
if (afterBackslash) {
|
1325
|
+
regexString = "\\\\" + regexString;
|
1326
|
+
}
|
1327
|
+
|
1328
|
+
var regex = new RegExp(regexString, "g");
|
1329
|
+
text = text.replace(regex, escapeCharacters_callback);
|
1330
|
+
|
1331
|
+
return text;
|
1332
|
+
};
|
1333
|
+
|
1356
1334
|
|
1357
|
-
var escapeCharacters_callback = function(wholeMatch,m1) {
|
1358
|
-
|
1359
|
-
|
1360
|
-
}
|
1335
|
+
var escapeCharacters_callback = function(wholeMatch, m1) {
|
1336
|
+
var charCodeToEscape = m1.charCodeAt(0);
|
1337
|
+
return "~E" + charCodeToEscape + "E";
|
1338
|
+
};
|
1361
1339
|
|
1362
|
-
}
|
1340
|
+
};
|