var esc = function (s) { return s; }; function getHtml() { var pendingFiles = [{ name: 'foo' }]; var text = 'bar'; var t = ''; if ((t.match(/\`\`\`/g) || []).length % 2 !== 0) t += '\\\\n\`\`\`'; var h = "var x = 1; // test"; h = h.replace(/(\\/, { 2: }[ ^ ], n, * ) / g, '$1'; ; h = h.replace(/(#[^\\\\n]*)/g, '$1'); h = h.replace(/(\\/, { 1: }, * [s, S] * ? : , * , /{1})/g, '$1'); h = h.replace(/("[^&]*?"|'[^&]*?')/g, '$1'); h = h.replace(/\\b(function|const|let|var|return|if|else|for|while|class|import|export|from|default|async|await|try|catch|throw|new|this|def|self|print|lambda|yield|with|as|raise|except|finally)\\b/g, '$1'); h = h.replace(/\\b(\\d+\\.?\\d*)\\b/g, '$1'); h = h.replace(/\\b(True|False|None|true|false|null|undefined|NaN)\\b/g, '$1'); h = h.replace(/\\b(String|Number|Boolean|Array|Object|Map|Set|Promise|void|int|float|str|list|dict|tuple)\\b/g, '$1'); h = h.replace(/([=!+\\-*/%|&^~?:]+)/g, '$1'); var displayText = text + (pendingFiles.length > 0 ? '\\\\n\\ud83d\\udcce ' + pendingFiles.map(function (f) { return f.name; }).join(', ') : ''); return "\n \n "); } console.log(getHtml());