Skip to content

Commit

Permalink
fix(srt): reader adds newline to multi-line cues
Browse files Browse the repository at this point in the history
  • Loading branch information
lideen committed Nov 28, 2024
1 parent 848aeee commit 67443e2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
3 changes: 0 additions & 3 deletions src/main/python/ttconv/srt/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,6 @@ def to_model(data_file: typing.IO, _config = None, progress_callback=lambda _: N
div.push_child(current_p)
subtitle_text = ""

if state is _State.TEXT_MORE:
current_p.push_child(model.Br(current_p.get_doc()))

subtitle_text += line

state = _State.TEXT_MORE
Expand Down
37 changes: 33 additions & 4 deletions src/test/python/test_srt_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

from ttconv.srt.reader import to_model
import ttconv.style_properties as styles
import ttconv.model as model



Expand Down Expand Up @@ -78,7 +79,7 @@ def test_bold(self):
def test_blank_lines(self):
# from https://en.wikipedia.org/wiki/SubRip
SAMPLE = """
1
00:02:16,612 --> 00:02:19,376
Senator, we're making
Expand Down Expand Up @@ -135,7 +136,7 @@ def test_italic_alt(self):
if e.get_style(styles.StyleProperties.FontStyle) == styles.FontStyleType.italic:
break
else:
self.fail()
self.fail()

def test_underline(self):
f = io.StringIO(r"""1
Expand All @@ -161,7 +162,7 @@ def test_underline_alt(self):
if text_decoration is not None and text_decoration.underline:
break
else:
self.fail()
self.fail()

def test_blue(self):
f = io.StringIO(r"""1
Expand Down Expand Up @@ -205,7 +206,35 @@ def test_long_hours(self):
363601,
doc.get_body().first_child().first_child().get_end()
)


def test_single_line_text(self):
f = io.StringIO(r"""1
101:00:00,000 --> 101:00:01,000
Hello
""")
doc = to_model(f)

p_children = list(doc.get_body().first_child().first_child())
self.assertEqual(len(p_children), 1)
self.assertIsInstance(p_children[0], model.Span)
self.assertEqual(p_children[0].first_child().get_text(), "Hello")

def test_multiline_text(self):
f = io.StringIO(r"""1
101:00:00,000 --> 101:00:01,000
Hello
World
""")
doc = to_model(f)

p_children = list(doc.get_body().first_child().first_child())
self.assertEqual(len(p_children), 3)
self.assertIsInstance(p_children[0], model.Span)
self.assertEqual(p_children[0].first_child().get_text(), "Hello")
self.assertIsInstance(p_children[1], model.Br)
self.assertIsInstance(p_children[2], model.Span)
self.assertEqual(p_children[2].first_child().get_text(), "World")


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

0 comments on commit 67443e2

Please sign in to comment.