|
@@ -1,13 +1,27 @@
|
|
|
/**
|
|
|
- * Created by Estevao on 11-01-2015.
|
|
|
+ * showdownjs helper functions
|
|
|
*/
|
|
|
|
|
|
-function isString(a) {
|
|
|
+if (!showdown.hasOwnProperty('helper')) {
|
|
|
+ showdown.helper = {};
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Check if var is string
|
|
|
+ * @param {string} a
|
|
|
+ * @returns {boolean}
|
|
|
+ */
|
|
|
+showdown.helper.isString = function isString(a) {
|
|
|
'use strict';
|
|
|
return (typeof a === 'string' || a instanceof String);
|
|
|
-}
|
|
|
+};
|
|
|
|
|
|
-function forEach(obj, callback) {
|
|
|
+/**
|
|
|
+ * ForEach helper function
|
|
|
+ * @param {*} obj
|
|
|
+ * @param {function} callback
|
|
|
+ */
|
|
|
+showdown.helper.forEach = function forEach(obj, callback) {
|
|
|
'use strict';
|
|
|
if (typeof obj.forEach === 'function') {
|
|
|
obj.forEach(callback);
|
|
@@ -17,64 +31,17 @@ function forEach(obj, callback) {
|
|
|
callback(obj[i], i, obj);
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
-
|
|
|
-function isArray(a) {
|
|
|
- 'use strict';
|
|
|
- return a.constructor === Array;
|
|
|
-}
|
|
|
-
|
|
|
-function isUndefined(value) {
|
|
|
- 'use strict';
|
|
|
- return typeof value === 'undefined';
|
|
|
-}
|
|
|
-
|
|
|
-var escapeCharactersCallback = function (wholeMatch, m1) {
|
|
|
- 'use strict';
|
|
|
- var charCodeToEscape = m1.charCodeAt(0);
|
|
|
- return '~E' + charCodeToEscape + 'E';
|
|
|
-};
|
|
|
-
|
|
|
-var escapeCharacters = function (text, charsToEscape, afterBackslash) {
|
|
|
- 'use strict';
|
|
|
- // First we have to escape the escape characters so that
|
|
|
- // we can build a character class out of them
|
|
|
- var regexString = '([' + charsToEscape.replace(/([\[\]\\])/g, '\\$1') + '])';
|
|
|
-
|
|
|
- if (afterBackslash) {
|
|
|
- regexString = '\\\\' + regexString;
|
|
|
- }
|
|
|
-
|
|
|
- var regex = new RegExp(regexString, 'g');
|
|
|
- text = text.replace(regex, escapeCharactersCallback);
|
|
|
-
|
|
|
- return text;
|
|
|
};
|
|
|
|
|
|
-if (!showdown.hasOwnProperty('helper')) {
|
|
|
- showdown.helper = {};
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * isString helper function
|
|
|
- * @param a
|
|
|
- * @returns {boolean}
|
|
|
- */
|
|
|
-showdown.helper.isString = isString;
|
|
|
-
|
|
|
-/**
|
|
|
- * ForEach helper function
|
|
|
- * @param {*} obj
|
|
|
- * @param callback
|
|
|
- */
|
|
|
-showdown.helper.forEach = forEach;
|
|
|
-
|
|
|
/**
|
|
|
* isArray helper function
|
|
|
* @param {*} a
|
|
|
* @returns {boolean}
|
|
|
*/
|
|
|
-showdown.helper.isArray = isArray;
|
|
|
+showdown.helper.isArray = function isArray(a) {
|
|
|
+ 'use strict';
|
|
|
+ return a.constructor === Array;
|
|
|
+};
|
|
|
|
|
|
/**
|
|
|
* Check if value is undefined
|
|
@@ -83,7 +50,10 @@ showdown.helper.isArray = isArray;
|
|
|
* @param {*} value The value to check.
|
|
|
* @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
|
|
|
*/
|
|
|
-showdown.helper.isUndefined = isUndefined;
|
|
|
+showdown.helper.isUndefined = function isUndefined(value) {
|
|
|
+ 'use strict';
|
|
|
+ return typeof value === 'undefined';
|
|
|
+};
|
|
|
|
|
|
/**
|
|
|
* Callback used to escape characters when passing through String.replace
|
|
@@ -91,7 +61,11 @@ showdown.helper.isUndefined = isUndefined;
|
|
|
* @param {string} m1
|
|
|
* @returns {string}
|
|
|
*/
|
|
|
-showdown.helper.escapeCharactersCallback = escapeCharactersCallback;
|
|
|
+showdown.helper.escapeCharactersCallback = function escapeCharactersCallback(wholeMatch, m1) {
|
|
|
+ 'use strict';
|
|
|
+ var charCodeToEscape = m1.charCodeAt(0);
|
|
|
+ return '~E' + charCodeToEscape + 'E';
|
|
|
+};
|
|
|
|
|
|
/**
|
|
|
* Escape characters in a string
|
|
@@ -101,4 +75,18 @@ showdown.helper.escapeCharactersCallback = escapeCharactersCallback;
|
|
|
* @param {boolean} afterBackslash
|
|
|
* @returns {XML|string|void|*}
|
|
|
*/
|
|
|
-showdown.helper.escapeCharacters = escapeCharacters;
|
|
|
+showdown.helper.escapeCharacters = function escapeCharacters(text, charsToEscape, afterBackslash) {
|
|
|
+ 'use strict';
|
|
|
+ // First we have to escape the escape characters so that
|
|
|
+ // we can build a character class out of them
|
|
|
+ var regexString = '([' + charsToEscape.replace(/([\[\]\\])/g, '\\$1') + '])';
|
|
|
+
|
|
|
+ if (afterBackslash) {
|
|
|
+ regexString = '\\\\' + regexString;
|
|
|
+ }
|
|
|
+
|
|
|
+ var regex = new RegExp(regexString, 'g');
|
|
|
+ text = text.replace(regex, escapeCharactersCallback);
|
|
|
+
|
|
|
+ return text;
|
|
|
+};
|