diff --git a/src/extension.ts b/src/extension.ts index df5d990..eb6911d 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1320,15 +1320,15 @@ let loader=null,sending=false,pendingFiles=[]; /* Syntax Highlighting (lightweight) */ function highlight(code,lang){ let h=esc(code); - h=h.replace(/(\\/\\/[^\\n]*)/g,'$1'); - h=h.replace(/(#[^\\n]*)/g,'$1'); - h=h.replace(/(\\/\\*[\\s\\S]*?\\*\\/)/g,'$1'); + h=h.replace(new RegExp("(\\\\/\\\\/[^\\\\n]*)", "g"),'$1'); + h=h.replace(new RegExp("(#[^\\\\n]*)", "g"),'$1'); + h=h.replace(new RegExp("(\\\\/\\\\*[\\\\s\\\\S]*?\\\\*\\\\/)", "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'); + h=h.replace(new RegExp("\\\\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(new RegExp("\\\\b(\\\\d+\\\\.?\\\\d*)\\\\b", "g"),'$1'); + h=h.replace(new RegExp("\\\\b(True|False|None|true|false|null|undefined|NaN)\\\\b", "g"),'$1'); + h=h.replace(new RegExp("\\\\b(String|Number|Boolean|Array|Object|Map|Set|Promise|void|int|float|str|list|dict|tuple)\\\\b", "g"),'$1'); + h=h.replace(/([=!+*/%|&^~?:-]+)/g,'$1'); return h; } @@ -1361,7 +1361,7 @@ function fmt(t){ if(t.lastIndexOf(' t.lastIndexOf('')) t += ''; if(t.lastIndexOf(' t.lastIndexOf('')) t += ''; if(t.lastIndexOf(' t.lastIndexOf('')) t += ''; - if((t.match(/\x60\x60\x60/g)||[]).length % 2 !== 0) t += '\\n\x60\x60\x60'; + if((t.match(/\x60\x60\x60/g)||[]).length % 2 !== 0) t += '\\\\n\x60\x60\x60'; const blocks = []; function pushB(h){ blocks.push(h); return '__B' + (blocks.length-1) + '__'; } @@ -1395,7 +1395,7 @@ function send(){ document.body.classList.remove('init'); const w=document.querySelector('.welcome');if(w)w.remove(); document.querySelectorAll('.quick-actions').forEach(e=>e.remove()); - const displayText=text+(pendingFiles.length>0?'\n\ud83d\udcce '+pendingFiles.map(f=>f.name).join(', '):''); + const displayText=text+(pendingFiles.length>0?'\\\\n\\ud83d\\udcce '+pendingFiles.map(f=>f.name).join(', '):''); addMsg(displayText,'user'); input.value='';input.style.height='auto';setSending(true);showLoader(); if(pendingFiles.length>0){