Skip to content

Commit 36348e8

Browse files
author
minjk-bl
committed
CHROME: Added marked and mathjaxutils for Markdown
1 parent 0c91b7c commit 36348e8

File tree

3 files changed

+2056
-1
lines changed

3 files changed

+2056
-1
lines changed

js/com/com_util.js

Lines changed: 114 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,117 @@ define([
265265
return label;
266266
}
267267

268+
//============================================================================
269+
// Cross-browser RegEx Split
270+
//============================================================================
271+
272+
// This code has been MODIFIED from the code licensed below to not replace the
273+
// default browser split. The license is reproduced here.
274+
275+
// see http://blog.stevenlevithan.com/archives/cross-browser-split for more info:
276+
/*!
277+
* Cross-Browser Split 1.1.1
278+
* Copyright 2007-2012 Steven Levithan <stevenlevithan.com>
279+
* Available under the MIT License
280+
* ECMAScript compliant, uniform cross-browser split method
281+
*/
282+
283+
/**
284+
* Splits a string into an array of strings using a regex or string
285+
* separator. Matches of the separator are not included in the result array.
286+
* However, if `separator` is a regex that contains capturing groups,
287+
* backreferences are spliced into the result each time `separator` is
288+
* matched. Fixes browser bugs compared to the native
289+
* `String.prototype.split` and can be used reliably cross-browser.
290+
* @param {String} str String to split.
291+
* @param {RegExp} separator Regex to use for separating
292+
* the string.
293+
* @param {Number} [limit] Maximum number of items to include in the result
294+
* array.
295+
* @returns {Array} Array of substrings.
296+
* @example
297+
*
298+
* // Basic use
299+
* regex_split('a b c d', ' ');
300+
* // -> ['a', 'b', 'c', 'd']
301+
*
302+
* // With limit
303+
* regex_split('a b c d', ' ', 2);
304+
* // -> ['a', 'b']
305+
*
306+
* // Backreferences in result array
307+
* regex_split('..word1 word2..', /([a-z]+)(\d+)/i);
308+
* // -> ['..', 'word', '1', ' ', 'word', '2', '..']
309+
*/
310+
var regex_split = function (str, separator, limit) {
311+
var output = [],
312+
flags = (separator.ignoreCase ? "i" : "") +
313+
(separator.multiline ? "m" : "") +
314+
(separator.extended ? "x" : "") + // Proposed for ES6
315+
(separator.sticky ? "y" : ""), // Firefox 3+
316+
lastLastIndex = 0,
317+
separator2, match, lastIndex, lastLength;
318+
// Make `global` and avoid `lastIndex` issues by working with a copy
319+
separator = new RegExp(separator.source, flags + "g");
320+
321+
var compliantExecNpcg = typeof(/()??/.exec("")[1]) === "undefined";
322+
if (!compliantExecNpcg) {
323+
// Doesn't need flags gy, but they don't hurt
324+
separator2 = new RegExp("^" + separator.source + "$(?!\\s)", flags);
325+
}
326+
/* Values for `limit`, per the spec:
327+
* If undefined: 4294967295 // Math.pow(2, 32) - 1
328+
* If 0, Infinity, or NaN: 0
329+
* If positive number: limit = Math.floor(limit); if (limit > 4294967295) limit -= 4294967296;
330+
* If negative number: 4294967296 - Math.floor(Math.abs(limit))
331+
* If other: Type-convert, then use the above rules
332+
*/
333+
limit = typeof(limit) === "undefined" ?
334+
-1 >>> 0 : // Math.pow(2, 32) - 1
335+
limit >>> 0; // ToUint32(limit)
336+
for (match = separator.exec(str); match; match = separator.exec(str)) {
337+
// `separator.lastIndex` is not reliable cross-browser
338+
lastIndex = match.index + match[0].length;
339+
if (lastIndex > lastLastIndex) {
340+
output.push(str.slice(lastLastIndex, match.index));
341+
// Fix browsers whose `exec` methods don't consistently return `undefined` for
342+
// nonparticipating capturing groups
343+
if (!compliantExecNpcg && match.length > 1) {
344+
match[0].replace(separator2, function () {
345+
for (var i = 1; i < arguments.length - 2; i++) {
346+
if (typeof(arguments[i]) === "undefined") {
347+
match[i] = undefined;
348+
}
349+
}
350+
});
351+
}
352+
if (match.length > 1 && match.index < str.length) {
353+
Array.prototype.push.apply(output, match.slice(1));
354+
}
355+
lastLength = match[0].length;
356+
lastLastIndex = lastIndex;
357+
if (output.length >= limit) {
358+
break;
359+
}
360+
}
361+
if (separator.lastIndex === match.index) {
362+
separator.lastIndex++; // Avoid an infinite loop
363+
}
364+
}
365+
if (lastLastIndex === str.length) {
366+
if (lastLength || !separator.test("")) {
367+
output.push("");
368+
}
369+
} else {
370+
output.push(str.slice(lastLastIndex));
371+
}
372+
return output.length > limit ? output.slice(0, limit) : output;
373+
};
374+
375+
//============================================================================
376+
// End contributed Cross-browser RegEx Split
377+
//============================================================================
378+
268379
return {
269380
getUUID: getUUID,
270381
loadCss: loadCss,
@@ -286,7 +397,9 @@ define([
286397
setIsAPIListRunCode: setIsAPIListRunCode,
287398
getIsAPIListRunCode: getIsAPIListRunCode,
288399
kernelExecute: kernelExecute,
289-
safeString: safeString
400+
safeString: safeString,
401+
402+
regex_split: regex_split
290403
}
291404

292405
}); /* function, define */

0 commit comments

Comments
 (0)