(text)
| 91 | * joined). Any prose before the first tag is attributed to the Narrator. |
| 92 | */ |
| 93 | export function parseTaggedScript(text) { |
| 94 | const out = []; |
| 95 | const src = String(text || '') |
| 96 | .replace(/\r\n/g, '\n') |
| 97 | .trim(); |
| 98 | if (!src) return out; |
| 99 | |
| 100 | let cur = { speaker: 'Narrator', parts: [] }; |
| 101 | const flush = () => { |
| 102 | const t = cur.parts.join('\n').trim(); |
| 103 | if (t) out.push({ speaker: cur.speaker, text: t }); |
| 104 | cur = { speaker: cur.speaker, parts: [] }; |
| 105 | }; |
| 106 | |
| 107 | for (const line of src.split('\n')) { |
| 108 | const m = line.match(_SPEAKER_TAG); |
| 109 | if (m && _isSpeakerTag(m[1])) { |
| 110 | flush(); |
| 111 | cur.speaker = normalizeSpeaker(m[1]); |
| 112 | if (m[2] && m[2].trim()) cur.parts.push(m[2].trim()); |
| 113 | } else if (line.trim()) { |
| 114 | cur.parts.push(line.trim()); |
| 115 | } |
| 116 | } |
| 117 | flush(); |
| 118 | return out; |
| 119 | } |
| 120 | |
| 121 | export function parseScript(text) { |
| 122 | const out = []; |
no test coverage detected