From 74d597afe3c1569c889b5311fb123aca838797db Mon Sep 17 00:00:00 2001 From: dwithana Date: Tue, 17 Dec 2024 10:10:06 -0500 Subject: [PATCH] Display line breaks within a cue for WebVTT and SRT transcripts --- src/services/transcript-parser.js | 5 +++++ src/services/transcript-parser.test.js | 24 ++++++++++++------------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/services/transcript-parser.js b/src/services/transcript-parser.js index b9e9c14f..0388c478 100644 --- a/src/services/transcript-parser.js +++ b/src/services/transcript-parser.js @@ -713,10 +713,15 @@ function groupTimedTextLines(lines) { t.line = isNote ? line.replace(/^NOTE\s*/, 'NOTE ') : ''; i++; + // Counter to keep track of lines within a cue + let cueLineCount = 0; // Increment until an empty line is encountered marking the end of the block while (i < lines.length && !(lines[i] == '\r' || lines[i] == '\n' || lines[i] == '\r\n' || lines[i] == '')) { + // Add a line break only between lines within a cue, omit start and end of cue + if (cueLineCount > 0) t.line += '
'; t.line += lines[i].endsWith('-') ? lines[i] : lines[i].replace(/\s*$/, ' '); + cueLineCount++; i++; } t.line = t.line.trimEnd(); diff --git a/src/services/transcript-parser.test.js b/src/services/transcript-parser.test.js index e003e90c..617a3a12 100644 --- a/src/services/transcript-parser.test.js +++ b/src/services/transcript-parser.test.js @@ -393,7 +393,7 @@ describe('transcript-parser', () => { { end: 26.6, begin: 22.2, - text: 'Just before lunch one day, a puppet show was put on at school.', + text: 'Just before lunch one day, a puppet show
was put on at school.', tag: 'TIMED_CUE' }, { @@ -411,7 +411,7 @@ describe('transcript-parser', () => { { end: 41.3, begin: 36.1, - text: "In the puppet show, Mr. Bungle came to the boys' room on his way to lunch.", + text: "In the puppet show, Mr. Bungle came to the
boys' room on his way to lunch.", tag: 'TIMED_CUE' }, ]; @@ -442,7 +442,7 @@ describe('transcript-parser', () => { { end: 26.6, begin: 22.2, - text: 'Just before lunch one day, a puppet show was put on at school.', + text: 'Just before lunch one day, a puppet show
was put on at school.', tag: 'TIMED_CUE' }, { @@ -460,7 +460,7 @@ describe('transcript-parser', () => { { end: 41.3, begin: 36.1, - text: "In the puppet show, Mr. Bungle came to the boys' room on his way to lunch.", + text: "In the puppet show, Mr. Bungle came to the
boys' room on his way to lunch.", tag: 'TIMED_CUE' }, ]; @@ -490,7 +490,7 @@ describe('transcript-parser', () => { { end: 26.6, begin: 22.2, - text: 'Just before lunch one day, a puppet show was put on at school.', + text: 'Just before lunch one day, a puppet show
was put on at school.', tag: 'TIMED_CUE' }, { @@ -508,7 +508,7 @@ describe('transcript-parser', () => { { end: 41.3, begin: 36.1, - text: "In the puppet show, Mr. Bungle came to the boys' room on his way to lunch.", + text: "In the puppet show, Mr. Bungle came to the
boys' room on his way to lunch.", tag: 'TIMED_CUE' }, ]; @@ -762,7 +762,7 @@ describe('transcript-parser', () => { tag: 'TIMED_CUE' }); expect(tData[4]).toEqual({ - text: "In the puppet show, Mr. Bungle came to the boys' room on his way to lunch.", + text: "In the puppet show, Mr. Bungle came to the
boys' room on his way to lunch.", begin: 36.1, end: 41.3, tag: 'TIMED_CUE' @@ -785,7 +785,7 @@ describe('transcript-parser', () => { tag: 'TIMED_CUE' }); expect(tData[4]).toEqual({ - text: "In the puppet show, Mr. Bungle came to the boys' room on his way to lunch.", + text: "In the puppet show, Mr. Bungle came to the
boys' room on his way to lunch.", begin: 36.1, end: 41.3, tag: 'TIMED_CUE' @@ -808,7 +808,7 @@ describe('transcript-parser', () => { tag: 'TIMED_CUE' }); expect(tData[4]).toEqual({ - text: "In the puppet show, Mr. Bungle came to the boys' room on his way to lunch.", + text: "In the puppet show, Mr. Bungle came to the
boys' room on his way to lunch.", begin: 36.1, end: 41.3, tag: 'TIMED_CUE' @@ -845,7 +845,7 @@ describe('transcript-parser', () => { tag: 'NOTE', begin: 0, end: 0, - text: 'NOTE This is a multi-line comment' + text: 'NOTE This is a multi-
line comment' }); expect(tType).toEqual(transcriptParser.TRANSCRIPT_TYPES.timedText); }); @@ -859,13 +859,13 @@ describe('transcript-parser', () => { expect(tData).toHaveLength(5); expect(tData[1]).toEqual({ - text: 'NOTE: Just before lunch one day, a puppet show was put on at school.', + text: 'NOTE: Just before lunch one day, a puppet show
was put on at school.', begin: 22.2, end: 26.6, tag: 'TIMED_CUE' }); expect(tData[4]).toEqual({ - text: 'In the puppet show, Mr. Bungle had a note to go to the boys\' room on his way to lunch.', + text: 'In the puppet show, Mr. Bungle had a
note to go to the boys\' room on his way to lunch.', begin: 36.1, end: 41.3, tag: 'TIMED_CUE'