/** * showdownjs helper functions */ if (!showdown.hasOwnProperty('helper')) { showdown.helper = {}; } /** * Check if var is string * @static * @param {string} a * @returns {boolean} */ showdown.helper.isString = function isString(a) { 'use strict'; return (typeof a === 'string' || a instanceof String); }; /** * ForEach helper function * @static * @param {*} obj * @param {function} callback */ showdown.helper.forEach = function forEach(obj, callback) { 'use strict'; if (typeof obj.forEach === 'function') { obj.forEach(callback); } else { for (var i = 0; i < obj.length; i++) { callback(obj[i], i, obj); } } }; /** * isArray helper function * @static * @param {*} a * @returns {boolean} */ showdown.helper.isArray = function isArray(a) { 'use strict'; return a.constructor === Array; }; /** * Check if value is undefined * @static * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`. */ showdown.helper.isUndefined = function isUndefined(value) { 'use strict'; return typeof value === 'undefined'; }; /** * Standardidize extension name * @static * @param {string} s extension name * @returns {string} */ showdown.helper.stdExtName = function (s) { 'use strict'; return s.replace(/[_-]||\s/g, '').toLowerCase(); }; function escapeCharactersCallback(wholeMatch, m1) { 'use strict'; var charCodeToEscape = m1.charCodeAt(0); return '~E' + charCodeToEscape + 'E'; } /** * Callback used to escape characters when passing through String.replace * @static * @param {string} wholeMatch * @param {string} m1 * @returns {string} */ showdown.helper.escapeCharactersCallback = escapeCharactersCallback; /** * Escape characters in a string * @static * @param {string} text * @param {string} charsToEscape * @param {boolean} afterBackslash * @returns {XML|string|void|*} */ 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; }; /** * POLYFILLS */ if (showdown.helper.isUndefined(console)) { console = { warn: function (msg) { 'use strict'; alert(msg); }, log: function (msg) { 'use strict'; alert(msg); } }; }