Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display line breaks within a cue for WebVTT and SRT transcripts #755

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/services/transcript-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 += '<br>';
t.line += lines[i].endsWith('-') ? lines[i] : lines[i].replace(/\s*$/, ' ');
cueLineCount++;
i++;
}
t.line = t.line.trimEnd();
Expand Down
24 changes: 12 additions & 12 deletions src/services/transcript-parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <br>was put on at school.',
tag: 'TIMED_CUE'
},
{
Expand All @@ -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 <br>boys' room on his way to lunch.",
tag: 'TIMED_CUE'
},
];
Expand Down Expand Up @@ -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 <br>was put on at school.',
tag: 'TIMED_CUE'
},
{
Expand All @@ -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 <br>boys' room on his way to lunch.",
tag: 'TIMED_CUE'
},
];
Expand Down Expand Up @@ -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 <br>was put on at school.',
tag: 'TIMED_CUE'
},
{
Expand All @@ -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 <br>boys' room on his way to lunch.",
tag: 'TIMED_CUE'
},
];
Expand Down Expand Up @@ -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 <br>boys' room on his way to lunch.",
begin: 36.1,
end: 41.3,
tag: 'TIMED_CUE'
Expand All @@ -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 <br>boys' room on his way to lunch.",
begin: 36.1,
end: 41.3,
tag: 'TIMED_CUE'
Expand All @@ -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 <br>boys' room on his way to lunch.",
begin: 36.1,
end: 41.3,
tag: 'TIMED_CUE'
Expand Down Expand Up @@ -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-<br>line comment'
});
expect(tType).toEqual(transcriptParser.TRANSCRIPT_TYPES.timedText);
});
Expand All @@ -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 <br>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 <br>note to go to the boys\' room on his way to lunch.',
begin: 36.1,
end: 41.3,
tag: 'TIMED_CUE'
Expand Down