with open('app.js', 'r', encoding='utf-8') as f: content = f.read() # The issue is the escapeHtml function has smart quotes # Find the line and replace with ASCII-only version lines = content.split('\n') for i, line in enumerate(lines): if 'escapeHtml' in line and 'function' in line: # Use chr() to build the replacement character map lines[i] = 'function escapeHtml(s) { return s.replace(/[&<>"\']/g, c => ({"&":"&","<":"<",">":">","\"":"\"","\'":"\'"}[c])); }' print(f'Fixed line {i+1}') with open('app.js', 'w', encoding='utf-8') as f: f.write('\n'.join(lines)) print('Done')