const fs = require('fs'); let code = fs.readFileSync('src/extension.ts', 'utf8'); let lines = code.split('\n'); const correctCode = `function fmt(t){ // Use new RegExp with string literals to avoid ALL JS parser escaping hell with regex literals containing forward slashes const createRe = new RegExp('([\\\\\\\\s\\\\\\\\S]*?)<\\\\\\\\/create_file>', 'g'); const editRe = new RegExp('([\\\\\\\\s\\\\\\\\S]*?)<\\\\\\\\/edit_file>', 'g'); const runRe = new RegExp('([\\\\\\\\s\\\\\\\\S]*?)<\\\\\\\\/run_command>', 'g'); const mdCodeRe = new RegExp('\\\\`\\\\`\\\\`(\\\\\\\\w*)\\\\\\\\n([\\\\\\\\s\\\\\\\\S]*?)\\\\`\\\\`\\\\`', 'g'); const inlineCodeRe = new RegExp('\\\\`([^\\\\`]+)\\\\`', 'g'); const boldRe = new RegExp('\\\\\\\\*\\\\\\\\*([^*]+)\\\\\\\\*\\\\\\\\*', 'g'); t=t.replace(createRe,(_,p,c)=>'
\\ud83d\\udcc1 '+esc(p)+' \\u2014 \\uc790\\ub3d9 \\uc0dd\\uc131\\ub428
'+esc(c)+'
'); t=t.replace(editRe,(_,p,c)=>'
\\u270f\\ufe0f '+esc(p)+' \\u2014 \\ud3b8\\uc9d1\\ub428
'+esc(c)+'
'); t=t.replace(runRe,(_,c)=>'
\\u25b6 '+esc(c)+'
'); t=t.replace(mdCodeRe,(_,lang,c)=>{const l=lang||'code';return '
'+l+'
'+esc(c)+'
'}); t=t.replace(inlineCodeRe,(_,c)=>''+esc(c)+''); t=t.replace(boldRe,'$1'); return t; }`; // Find where function fmt(t){ starts and replace it let start = lines.findIndex(l => l.includes('function fmt(t){')); let end = lines.findIndex((l, i) => i > start && l.includes('return t;')) + 1; lines.splice(start, end - start + 1, correctCode); fs.writeFileSync('src/extension.ts', lines.join('\n')); console.log('Fixed regex lines with RegExp approach!');