Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(srt): reader adds newline to multi-line cues #435

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()