The generated JavaScript used manual single-quote escaping
(replace(/\\/g, '\\\\').replace(/'/g, \"'\\\\''\")) which missed
newlines, carriage returns, and other special characters. Captions
containing line breaks would produce syntactically broken JS.
Use JSON.stringify which handles all JS string special characters
correctly, including newlines, unicode, and control characters.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>