import test from 'node:test'; import assert from 'node:assert/strict'; import { parseHTML } from 'linkedom'; import { exportCaptionSource } from '../shared/caption-export.ts'; import { fixture } from './fixtures.ts'; import { Phase1Service } from '../phase1.ts'; import { pluginRoot } from '../hyperframes.ts'; const root = (cues: string) => `
${cues}
`; const cue = (text: string, start: number, duration: number, attrs = '') => `
${text}
`; test('exports saved caption text, timing, multiline entities, trim and hidden state', () => { const source = root(cue('Later', 4, 8) + cue('Edited & styled
line', 1, 2) + cue('Hidden', 0, 1, 'data-hidden') + cue('Title', 0, 1, 'data-timeline-role="text"').replace('data-timeline-role="caption"', '')); const result = exportCaptionSource(source, 'srt', parseHTML); assert.equal(result.cueCount, 2); assert.equal(result.content, '1\n00:00:01,000 --> 00:00:03,000\nEdited & styled\nline\n\n2\n00:00:04,000 --> 00:00:06,000\nLater\n'); assert.match(exportCaptionSource(source, 'vtt', parseHTML).content, /^WEBVTT\n\n1\n00:00:01.000/); }); test('WebVTT export escapes cue text that would otherwise read as markup; SRT stays plain', () => { const source = root(cue('Tom & Jerry <3 Q&A', 0, 1) + cue('Use the <video> tag if a < b --> c', 1, 1)); assert.equal(exportCaptionSource(source, 'vtt', parseHTML).content, 'WEBVTT\n\n1\n00:00:00.000 --> 00:00:01.000\nTom & Jerry <3 Q&A\n\n2\n00:00:01.000 --> 00:00:02.000\nUse the <video> tag if a < b --> c\n'); assert.equal(exportCaptionSource(source, 'srt', parseHTML).content, '1\n00:00:00,000 --> 00:00:01,000\nTom & Jerry <3 Q&A\n\n2\n00:00:01,000 --> 00:00:02,000\nUse the