Serialization
Most formats provide to<Format>(doc) to serialize a SubtitleDocument:
ts
import { toSRT } from 'subforge/srt'
import { toASS } from 'subforge/ass'
const srt = toSRT(doc)
const ass = toASS(doc)Serializer behavior
- If
event.dirtyisfalse, serializers can reuseevent.textfor lossless roundtrip. - If you edit
segments, setdirty = trueto regenerate text. - Bitmap formats (PGS, DVB, VobSub) read image payloads from
event.imageand metadata fromevent.pgsorevent.vobsub.
Format-specific options
Some serializers accept options (examples):
ts
import { toTTML } from 'subforge/ttml'
import { toCAP } from 'subforge/cap'
import type { CAPSerializerOptions } from 'subforge/cap'
const ttml = toTTML(doc, { format: 'clock' })
const options: CAPSerializerOptions = { videoStandard: 'PAL' }
const cap = toCAP(doc, options)