/
text.srt.js
278 lines (277 loc) · 9.91 KB
/
text.srt.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
// This is a TextMate grammar distributed by `starry-night`.
// This grammar is developed at
// <https://github.com/Alhadis/language-subtitles>
// and licensed `isc`.
// See <https://github.com/wooorm/starry-night> for more info.
/** @type {import('../lib/index.js').Grammar} */
const grammar = {
dependencies: ['text.html.basic'],
extensions: [],
names: ['subrip-text'],
patterns: [{include: '#main'}],
repository: {
action: {
patterns: [
{
begin: '\\[',
beginCaptures: {0: {name: 'punctuation.definition.string.begin.srt'}},
end: '\\]|(?=^[ \\t]*$)',
endCaptures: {0: {name: 'punctuation.definition.string.end.srt'}},
name: 'string.quoted.other.sound.action.square-brackets.srt',
patterns: [{include: '#formatting'}]
},
{
begin: '\\(',
beginCaptures: {0: {name: 'punctuation.definition.string.begin.srt'}},
end: '\\)|(?=^[ \\t]*$)',
endCaptures: {0: {name: 'punctuation.definition.string.end.srt'}},
name: 'string.quoted.other.sound.action.round-brackets.srt',
patterns: [{include: '#formatting'}]
}
]
},
align: {
captures: {
1: {name: 'punctuation.definition.tag.begin.srt'},
2: {name: 'entity.name.tag.srt'},
3: {name: 'invalid.deprecated.syntax.tag.srt'},
4: {name: 'punctuation.definition.tag.end.srt'}
},
match: '({)(\\\\a(?:n[1-9]|(10|11|(?!4|8)\\d)))(})',
name: 'meta.tag.override.line-alignment.srt'
},
arrow: {
captures: {0: {name: 'punctuation.definition.separator.srt'}},
match: '-->',
name: 'keyword.operator.timespan.srt'
},
bold: {
begin: '(<)([Bb])(?=$|>|\\s)([^>]*)(>)',
beginCaptures: {
0: {name: 'meta.tag.inline.b.html.srt'},
1: {name: 'punctuation.definition.tag.begin.html.srt'},
2: {name: 'entity.name.tag.inline.b.html.srt'},
3: {patterns: [{include: 'text.html.basic#tag-stuff'}]},
4: {name: 'punctuation.definition.tag.end.html.srt'}
},
contentName: 'markup.bold.srt',
end: '(</)([Bb])[ \\t]*(>)|(?=^[ \\t]*$)',
endCaptures: {
0: {name: 'meta.tag.inline.b.html.srt'},
1: {name: 'punctuation.definition.tag.begin.html.srt'},
2: {name: 'entity.name.tag.inline.b.html'},
3: {name: 'punctuation.definition.tag.end.html.srt'}
},
patterns: [{include: '#text'}]
},
dash: {
captures: {1: {name: 'punctuation.section.quote.srt'}},
match: '(?:^|\\G)(-)',
name: 'markup.quote.quotation-dash.srt'
},
escapes: {
patterns: [
{
captures: {1: {name: 'punctuation.definition.escape.backslash.srt'}},
match: '(\\\\)h',
name: 'constant.character.whitespace.escape.hard-space.srt'
},
{
captures: {1: {name: 'punctuation.definition.escape.backslash.srt'}},
match: '(\\\\)N',
name: 'constant.character.whitespace.escape.forced-newline.srt'
}
]
},
font: {
begin: '(?i)(<)(font)(?=$|>|\\s)([^>]*)(>)',
beginCaptures: {
0: {name: 'meta.tag.inline.font.html.srt'},
1: {name: 'punctuation.definition.tag.begin.html.srt'},
2: {name: 'entity.name.tag.inline.font.html.srt'},
3: {patterns: [{include: 'text.html.basic#tag-stuff'}]},
4: {name: 'punctuation.definition.tag.end.html.srt'}
},
contentName: 'markup.other.font.srt',
end: '(?i)(</)(font)[ \\t]*(>)|(?=^[ \\t]*$)',
endCaptures: {
0: {name: 'meta.tag.inline.font.html.srt'},
1: {name: 'punctuation.definition.tag.begin.html.srt'},
2: {name: 'entity.name.tag.inline.font.html.srt'},
3: {name: 'punctuation.definition.tag.end.html.srt'}
},
patterns: [{include: '#text'}]
},
formatting: {
patterns: [
{include: '#bold'},
{include: '#italic'},
{include: '#underline'},
{include: '#strike'},
{include: '#font'},
{include: '#align'}
]
},
italic: {
begin: '(<)([Ii])(?=$|>|\\s)([^>]*)(>)',
beginCaptures: {
0: {name: 'meta.tag.inline.i.html.srt'},
1: {name: 'punctuation.definition.tag.begin.html.srt'},
2: {name: 'entity.name.tag.inline.i.html.srt'},
3: {patterns: [{include: 'text.html.basic#tag-stuff'}]},
4: {name: 'punctuation.definition.tag.end.html.srt'}
},
contentName: 'markup.italic.srt',
end: '(</)([Ii])[ \\t]*(>)|(?=^[ \\t]*$)',
endCaptures: {
0: {name: 'meta.tag.inline.i.html.srt'},
1: {name: 'punctuation.definition.tag.begin.html.srt'},
2: {name: 'entity.name.tag.inline.i.html'},
3: {name: 'punctuation.definition.tag.end.html.srt'}
},
patterns: [{include: '#text'}]
},
linePosition: {
captures: {
1: {name: 'variable.parameter.position.srt'},
3: {name: 'keyword.operator.assignment.key-value.colon.srt'},
4: {name: 'constant.numeric.float.srt'},
5: {name: 'constant.numeric.integer.srt'}
},
match: '\\b(([XY])[0-9]+)(:)(?:([-+]?[0-9]+\\.[0-9]+)|([-+]?[0-9]+))\\b',
name: 'meta.line-position.${2:/downcase}-axis.srt'
},
lyrics: {
begin: '(♪+)[ \\t]*',
beginCaptures: {1: {name: 'punctuation.definition.lyrics.begin.srt'}},
end: '[ \\t]*(♪+)|(?=^-|^[ \\t]*$|\\s*</)',
endCaptures: {1: {name: 'punctuation.definition.lyrics.end.srt'}},
name: 'markup.quote.lyrics.srt',
patterns: [{include: '#formatting'}]
},
main: {patterns: [{include: '#subtitle'}]},
speaker: {
captures: {
1: {patterns: [{include: '#dash'}]},
2: {
name: 'entity.name.speaker.srt',
patterns: [{include: '#formatting'}, {include: '#action'}]
},
3: {name: 'punctuation.separator.speaker.colon.srt'}
},
match:
'(?:^|\\G)(-[ \\t]*)?((?:[^-<>\\s:][^:]*(?=:[ \\t]*\\S)|[^-<>\\s:a-z][^:a-z]*)(:))(?=$|\\s)'
},
strike: {
begin: '(<)([Ss])(?=$|>|\\s)([^>]*)(>)',
beginCaptures: {
0: {name: 'meta.tag.inline.s.html.srt'},
1: {name: 'punctuation.definition.tag.begin.html.srt'},
2: {name: 'entity.name.tag.inline.s.html.srt'},
3: {patterns: [{include: 'text.html.basic#tag-stuff'}]},
4: {name: 'punctuation.definition.tag.end.html.srt'}
},
contentName: 'markup.strike.srt',
end: '(</)([Ss])[ \\t]*(>)|(?=^[ \\t]*$)',
endCaptures: {
0: {name: 'meta.tag.inline.s.html.srt'},
1: {name: 'punctuation.definition.tag.begin.html.srt'},
2: {name: 'entity.name.tag.inline.s.html'},
3: {name: 'punctuation.definition.tag.end.html.srt'}
},
patterns: [{include: '#text'}]
},
subtitle: {
begin: '^(?:?)(\\d+)$',
beginCaptures: {1: {name: 'entity.name.section.srt'}},
end: '^[ \\t]*$',
name: 'meta.subtitle.srt',
patterns: [
{
begin: '\\G\\s*',
end: '(?!\\G)$',
patterns: [
{
begin:
'(?x) ^\n([0-9]{2}:[0-9]{2}:[0-9]{2}[,.][0-9]{3}) \\x20(-->)\\x20 (\\1)\n((?:\\s*[XY][0-9]+:[-+]?[0-9]+(?:\\.[0-9]+)?)++)?\n[ \\t]* $ ',
beginCaptures: {
1: {
name: 'constant.numeric.time.timecode.start.srt',
patterns: [{include: '#timecode'}]
},
2: {patterns: [{include: '#arrow'}]},
3: {
name: 'constant.numeric.time.timecode.end.srt',
patterns: [{include: '#timecode'}]
},
4: {patterns: [{include: '#linePosition'}]}
},
contentName: 'comment.block.ignored.hidden-subtitle.srt',
end: '(?=^[ \\t]*$)',
name: 'meta.timespan.empty.srt'
},
{
captures: {
1: {
name: 'constant.numeric.time.timecode.start.srt',
patterns: [{include: '#timecode'}]
},
2: {patterns: [{include: '#arrow'}]},
3: {
name: 'constant.numeric.time.timecode.end.srt',
patterns: [{include: '#timecode'}]
},
4: {patterns: [{include: '#linePosition'}]}
},
match:
'(?x) ^\n([0-9]{2}:[0-9]{2}:[0-9]{2}[,.][0-9]{3}) \\x20(-->)\\x20\n([0-9]{2}:[0-9]{2}:[0-9]{2}[,.][0-9]{3})\n((?:\\s*[XY][0-9]+:[-+]?[0-9]+(?:\\.[0-9]+)?)++)?\n[ \\t]* $ ',
name: 'meta.timespan.srt'
},
{include: '#text'}
]
},
{include: '#text'}
]
},
text: {
patterns: [
{include: '#speaker'},
{include: '#dash'},
{include: '#action'},
{include: '#lyrics'},
{include: '#formatting'},
{include: '#escapes'}
]
},
timecode: {
patterns: [
{match: '\\.', name: 'invalid.illegal.syntax.decimal-separator.srt'},
{
match: '(?<=:)([6-9][0-9])',
name: 'invalid.illegal.value.out-of-range.vtt'
}
]
},
underline: {
begin: '(<)([Uu])(?=$|>|\\s)([^>]*)(>)',
beginCaptures: {
0: {name: 'meta.tag.inline.u.html.srt'},
1: {name: 'punctuation.definition.tag.begin.html.srt'},
2: {name: 'entity.name.tag.inline.u.html.srt'},
3: {patterns: [{include: 'text.html.basic#tag-stuff'}]},
4: {name: 'punctuation.definition.tag.end.html.srt'}
},
contentName: 'markup.underline.srt',
end: '(</)([Uu])[ \\t]*(>)|(?=^[ \\t]*$)',
endCaptures: {
0: {name: 'meta.tag.inline.u.html.srt'},
1: {name: 'punctuation.definition.tag.begin.html.srt'},
2: {name: 'entity.name.tag.inline.u.html'},
3: {name: 'punctuation.definition.tag.end.html.srt'}
},
patterns: [{include: '#text'}]
}
},
scopeName: 'text.srt'
}
export default grammar