|
35 | 35 | linePos = 0,
|
36 | 36 | lines = input.split(NEWLINE),
|
37 | 37 | alreadyCollected = false,
|
| 38 | + styles = [], |
38 | 39 | cues = [],
|
39 | 40 | errors = []
|
40 | 41 | function err(message, col) {
|
|
121 | 122 | continue
|
122 | 123 | }
|
123 | 124 |
|
| 125 | + /* STYLES */ |
| 126 | + if(/^STYLE($|[ \t])/.test(cue.id)) { |
| 127 | + var style = [] |
| 128 | + var invalid = false |
| 129 | + linePos++ |
| 130 | + while(lines[linePos] != "" && lines[linePos] != undefined) { |
| 131 | + if(lines[linePos].indexOf("-->") != -1) { |
| 132 | + err("Cannot have timestamp in a style block.") |
| 133 | + invalid = true |
| 134 | + } |
| 135 | + style.push(lines[linePos]) |
| 136 | + linePos++ |
| 137 | + } |
| 138 | + if(cues.length) { |
| 139 | + err("Style blocks cannot appear after the first cue.") |
| 140 | + continue |
| 141 | + } |
| 142 | + if (!invalid) { |
| 143 | + styles.push(style.join('\n')) |
| 144 | + } |
| 145 | + continue |
| 146 | + } |
| 147 | + |
124 | 148 | linePos++
|
125 | 149 |
|
126 | 150 | if(lines[linePos] == "" || lines[linePos] == undefined) {
|
|
190 | 214 | return 0
|
191 | 215 | })
|
192 | 216 | /* END */
|
193 |
| - return {cues:cues, errors:errors, time:Date.now()-startTime} |
| 217 | + return {cues:cues, errors:errors, time:Date.now()-startTime, styles: styles} |
194 | 218 | }
|
195 | 219 | }
|
196 | 220 |
|
|
836 | 860 | + serializeCueSettings(cue)
|
837 | 861 | + "\n" + serializeTree(cue.tree.children) + "\n\n"
|
838 | 862 | }
|
839 |
| - this.serialize = function(cues) { |
| 863 | + function serializeStyle(style) { |
| 864 | + return "STYLE\n" + style + "\n\n" |
| 865 | + } |
| 866 | + this.serialize = function(cues, styles) { |
840 | 867 | var result = "WEBVTT\n\n"
|
| 868 | + if (styles) { |
| 869 | + for(var i=0;i<styles.length;i++) { |
| 870 | + result += serializeStyle(styles[i]) |
| 871 | + } |
| 872 | + } |
841 | 873 | for(var i=0;i<cues.length;i++) {
|
842 | 874 | result += serializeCue(cues[i])
|
843 | 875 | }
|
|
0 commit comments