DDH.cheat_sheets = DDH.cheat_sheets || {}; DDH.cheat_sheets.build = function(ops) { Spice.registerHelper('cheatsheets_ordered', function(sections, section_order, template_type, options) { var result = ""; var template = { type: template_type, path: template_type ? 'DDH.cheat_sheets.' + template_type : 'DDH.cheat_sheets.keyboard' }; $.each(section_order, function(i, section) { if (sections[section]){ var showhide = true; if (i === 0 ){ showhide = false; } else if ( i === 1 && !is_mobile ){ showhide = false; } //replaces */ and /* to */ and /* fixing issue1646 var val; for (var j = 0; j < sections[section].length; j++){ if (sections[section][j].hasOwnProperty(val)){ sections[section][j].val.replace(/*//g, "*/") .replace(//*/g, "/*"); } } result += options.fn({ name: section, items: sections[section], template: template, showhide: showhide }); } }); return result; }); var re_brackets = /(?:\[|\{|\}|\])/, // search for [, {, }, or } re_whitespace = /\s+/, // search for spaces re_codeblock = /(.+?)<\/code>/g; // search for Spice.registerHelper('cheatsheets_codeblock', function(string, className, options) { var out; var codeClass = typeof className === "string" ? className : "bg-clr--white"; // replace escaped slashes and brackets string = string.replace(/\/g, '>') .replace(/\\\\/, "") .replace(/\\\[/g, "") .replace(/\\\{/g, "") .replace(/\\\]/g, "") .replace(/\\\}/g, ""); // no spaces // OR // spaces and no un-escaped brackets // e.g "?()", ":sp filename" // --> wrap whole sting in if ( !re_whitespace.test(string) || !re_brackets.test(string) ){ out = "" + string + ""; // spaces // AND // un-escaped brackets // e.g "[Ctrl] [B]" // --> replace [] & {} with } else { // replace unescaped brackets out = string .replace(/\[|\{/g, "") .replace(/\]|\}/g, ""); } out = out // re-replace escaped slash .replace(//g, "\\") // re-replace escaped brackets .replace(//g, "[") .replace(//g, "{") .replace(//g, "]") .replace(//g, "}"); out = out.replace(re_codeblock, function esc_codeblock (match, p1, offset, string, codeClass){ var escaped = Handlebars.Utils.escapeExpression(p1); return "