import sys with open('src/extension.ts', 'r') as f: text = f.read() start_idx = text.find('function fmt(t){') end_idx = text.find('function copyCode(btn)') # I will avoid ALL slashes and regex literals entirely, and use purely new RegExp("...", "g") syntax with properly escaped backslashes for JS strings. new_fmt = """function fmt(t){ t=t.replace(new RegExp('([\\\\\\\\s\\\\\\\\S]*?)<\\\\\\\\/create_file>', 'g'),(_,p,c)=>'
\\uD83D\\uDCC1 '+esc(p)+' \\u2014 \\uC790\\uB3D9 \\uC0DD\\uC131\\uB428
'+esc(c)+'
'); t=t.replace(new RegExp('([\\\\\\\\s\\\\\\\\S]*?)<\\\\\\\\/edit_file>', 'g'),(_,p,c)=>'
\\u270F\\uFE0F '+esc(p)+' \\u2014 \\uD3B8\\uC9D1\\uB428
'+esc(c)+'
'); t=t.replace(new RegExp('([\\\\\\\\s\\\\\\\\S]*?)<\\\\\\\\/run_command>', 'g'),(_,c)=>'
\\u25B6 '+esc(c)+'
'); t=t.replace(new RegExp('\\\\\\\\`\\\\\\\\`\\\\\\\\`(\\\\\\\\w*)\\\\\\\\n([\\\\\\\\s\\\\\\\\S]*?)\\\\\\\\`\\\\\\\\`\\\\\\\\`', 'g'),(_,lang,c)=>{const l=lang||'code';return '
'+l+'
'+esc(c)+'
'}); t=t.replace(new RegExp('\\\\\\\\`([^\\\\\\\\`]+)\\\\\\\\`', 'g'),(_,c)=>''+esc(c)+''); t=t.replace(new RegExp('\\\\\\\\*\\\\\\\\*([^*]+)\\\\\\\\*\\\\\\\\*', 'g'),'$1'); return t; } """ if start_idx != -1 and end_idx != -1: text = text[:start_idx] + new_fmt + text[end_idx:] with open('src/extension.ts', 'w') as f: f.write(text) print("Fixed!")