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

WebVTT: support styled cues and voice spans #218

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mbklein
Copy link
Member

@mbklein mbklein commented Jun 6, 2024

This PR adds support for advanced WebVTT features such as text formatting, CSS styling, voice spans, and Ruby characters.

To do so, I had to switch VTT parsing from node-webvtt to vtt.js. vtt.js is older, but neither of them has seen significant development in years, so I'm going with the theory that the lack of activity means more "stable" and less "abandoned."

The main advantage of this approach is access to the WebVTT.convertCueToDOMTree() method, which converts each WebVTT cue to a DOM DocumentFragment according to the guidelines laid out in Section 6.5 of the WebVTT W3C recommendation. This allows the consuming application to style cues according to class or voice in addition to stripping out any other tags that shouldn't be there.

Behavior for untagged cues is unchanged.

Example

Cue

00:00:02.320 --> 00:00:04.062
<v interviewer>How did you meet your wife?</v>

Before

&lt;v interviewer&gt;How did you meet your wife?&lt;/v&gt;
<strong>0:02</strong>

SCR-20240606-nyki

After (with styling applied to the resulting .webvtt-cue [title="..."] selectors)

<div class="webvtt-cue">
  <span title="interviewer">How did you meet your wife?</span>
</div>
<strong>0:02</strong>

SCR-20240606-nxii

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant