(source: string)
| 105 | * Returns an empty array if no transcript is found or if parsing fails. |
| 106 | */ |
| 107 | export function extractTranscript(source: string): TranscriptWord[] { |
| 108 | // Match: (const|let|var) (TRANSCRIPT|script) = [...] |
| 109 | // The array may span multiple lines and contain trailing commas. |
| 110 | // The lazy [\s\S]*? anchors on the first `];` — assumes transcript word |
| 111 | // text never contains a literal `];` string (safe for speech transcripts). |
| 112 | const varPattern = /(?:const|let|var)\s+(?:TRANSCRIPT|script)\s*=\s*(\[[\s\S]*?\]);/; |
| 113 | const match = source.match(varPattern); |
| 114 | |
| 115 | if (!match) { |
| 116 | return []; |
| 117 | } |
| 118 | |
| 119 | const arrayLiteral = match[1]; |
| 120 | |
| 121 | try { |
| 122 | return parseTranscriptArray(arrayLiteral); |
| 123 | } catch { |
| 124 | return []; |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Parses a caption composition from a live iframe DOM, extracting the transcript |
no test coverage detected