w3c / webvtt.js

WebVTT parser and validator
https://w3c.github.io/webvtt.js/parser.html
Creative Commons Zero v1.0 Universal
148 stars 49 forks source link

Serializer: Fallback to `tree` property if unavailable #13

Open saschanaz opened 6 years ago

saschanaz commented 6 years ago

Currently I'm trying to write an ASS-to-VTT converter which generates VTTCue-like structures.

The WebVTTSerializer also expects VTTCue-like objects but it expects parser-specific tree property, blocking my library to use it directly.

It may fallback to text if tree is unavailable, what do you think?

(This will also enable compatibility with native VTTCue):

new WebVTTSerializer().serialize([new VTTCue(0, 0, 'wow')])
// Currently throws with TypeError: cue.tree is undefined
annevk commented 6 years ago

If documented I suppose I wouldn't oppose, but can you not generate the required wrapper? An object with a children member which contains an array of a single object type is "text", etc.

saschanaz commented 6 years ago

I can, but I hope I wouldn't be required to do that. IMO using tree without debugging purpose is an unneeded overhead when we already have completely serialized text property.

annevk commented 6 years ago

I see, I had missed the parenthetical in OP.