mirror of
https://github.com/hanzoai/frames.git
synced 2026-09-24 00:08:03 +00:00
fix: use JSON.stringify for caption text escaping in generated JS
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 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
b1436a867f
commit
ab49fffba3
@@ -303,14 +303,14 @@ function generateJs(model: CaptionModel): string {
|
||||
|
||||
// Build word spans
|
||||
const wordLines: string[] = groupSegments.map((seg) => {
|
||||
const escaped = seg.text.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
||||
const escaped = JSON.stringify(seg.text);
|
||||
const segVar = `w_${seg.id.replace(/[^a-zA-Z0-9_]/g, "_")}`;
|
||||
const idLine = seg.wordId ? `\n ${segVar}.id = ${JSON.stringify(seg.wordId)};` : "";
|
||||
return (
|
||||
` const ${segVar} = document.createElement('span');` +
|
||||
`\n ${segVar}.className = 'word clip';` +
|
||||
idLine +
|
||||
`\n ${segVar}.textContent = '${escaped}';` +
|
||||
`\n ${segVar}.textContent = ${escaped};` +
|
||||
`\n ${segVar}.dataset.start = '${seg.start}';` +
|
||||
`\n ${segVar}.dataset.end = '${seg.end}';` +
|
||||
`\n groupEl_${groupVar}.appendChild(${segVar});`
|
||||
|
||||
Reference in New Issue
Block a user