Skip to content

Commit 1a8c6a5

Browse files
authored
SRT reader: remove extraneous line break in multi-line cues
#436
1 parent 848aeee commit 1a8c6a5

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

src/main/python/ttconv/srt/reader.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,6 @@ def to_model(data_file: typing.IO, _config = None, progress_callback=lambda _: N
256256
div.push_child(current_p)
257257
subtitle_text = ""
258258

259-
if state is _State.TEXT_MORE:
260-
current_p.push_child(model.Br(current_p.get_doc()))
261-
262259
subtitle_text += line
263260

264261
state = _State.TEXT_MORE

src/test/python/test_srt_reader.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
from ttconv.srt.reader import to_model
3333
import ttconv.style_properties as styles
34+
import ttconv.model as model
3435

3536

3637

@@ -78,7 +79,7 @@ def test_bold(self):
7879
def test_blank_lines(self):
7980
# from https://en.wikipedia.org/wiki/SubRip
8081
SAMPLE = """
81-
82+
8283
1
8384
00:02:16,612 --> 00:02:19,376
8485
Senator, we're making
@@ -135,7 +136,7 @@ def test_italic_alt(self):
135136
if e.get_style(styles.StyleProperties.FontStyle) == styles.FontStyleType.italic:
136137
break
137138
else:
138-
self.fail()
139+
self.fail()
139140

140141
def test_underline(self):
141142
f = io.StringIO(r"""1
@@ -161,7 +162,7 @@ def test_underline_alt(self):
161162
if text_decoration is not None and text_decoration.underline:
162163
break
163164
else:
164-
self.fail()
165+
self.fail()
165166

166167
def test_blue(self):
167168
f = io.StringIO(r"""1
@@ -205,7 +206,35 @@ def test_long_hours(self):
205206
363601,
206207
doc.get_body().first_child().first_child().get_end()
207208
)
208-
209+
210+
def test_single_line_text(self):
211+
f = io.StringIO(r"""1
212+
101:00:00,000 --> 101:00:01,000
213+
Hello
214+
""")
215+
doc = to_model(f)
216+
217+
p_children = list(doc.get_body().first_child().first_child())
218+
self.assertEqual(len(p_children), 1)
219+
self.assertIsInstance(p_children[0], model.Span)
220+
self.assertEqual(p_children[0].first_child().get_text(), "Hello")
221+
222+
def test_multiline_text(self):
223+
f = io.StringIO(r"""1
224+
101:00:00,000 --> 101:00:01,000
225+
Hello
226+
World
227+
""")
228+
doc = to_model(f)
229+
230+
p_children = list(doc.get_body().first_child().first_child())
231+
self.assertEqual(len(p_children), 3)
232+
self.assertIsInstance(p_children[0], model.Span)
233+
self.assertEqual(p_children[0].first_child().get_text(), "Hello")
234+
self.assertIsInstance(p_children[1], model.Br)
235+
self.assertIsInstance(p_children[2], model.Span)
236+
self.assertEqual(p_children[2].first_child().get_text(), "World")
237+
209238

210239
if __name__ == '__main__':
211240
unittest.main()

0 commit comments

Comments
 (0)