123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- /**
- * 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);
- }
- };
- }
|