Skip to content

🎥 Make videos programmatically with React

Preserve arrows in SRT caption text

Muhammed Furkan Akıncıf50bfd7beec0
diff --git a/packages/captions/src/parse-srt.ts b/packages/captions/src/parse-srt.ts
index 31066b7e67..942330c846 100644
--- a/packages/captions/src/parse-srt.ts
+++ b/packages/captions/src/parse-srt.ts
@@ -61,8 +61,7 @@ export const parseSrt = ({input}: ParseSrtInput): ParseSrtOutput => {
confidence: 1,
timestampMs: ((start + end) / 2) * 1000,
});
- } else if (line?.includes(' --> ')) {
- continue;
+ i++;
} else if (line?.trim() === '') {
if (captions.length > 0) {
(captions[captions.length - 1] as Caption).text = (
diff --git a/packages/captions/src/test/srt.test.ts b/packages/captions/src/test/srt.test.ts
index 7754a5b844..116933caca 100644
--- a/packages/captions/src/test/srt.test.ts
+++ b/packages/captions/src/test/srt.test.ts
@@ -47,6 +47,18 @@ test('Should create captions', () => {
expect(serialized).toEqual(input);
});
+test.each(['Left --> right\nAnother line', '00:00:03,000 --> 00:00:04,000'])(
+ 'Keeps arrows in SRT caption text: %s',
+ (text) => {
+ const srt = `1\n00:00:00,000 --> 00:00:01,000\n${text}`;
+ const {captions} = parseSrt({input: srt});
+
+ expect(captions).toHaveLength(1);
+ expect(captions[0].text).toBe(text);
+ expect(serializeSrt({lines: [captions]})).toBe(srt);
+ },
+);
+
test('Should start a new SRT cue after a forced page break', () => {
const serialized = serializeSrt({
lines: [