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 27, 2024
1 parent 848aeee commit 3965486
Show file tree
Hide file tree
Showing 2 changed files with 29 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
33 changes: 29 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,31 @@ def test_long_hours(self):
363601,
doc.get_body().first_child().first_child().get_end()
)


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

self.assertIsInstance(
doc.get_body().first_child().first_child().first_child(),
model.Span
)

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

self.assertIsInstance(
doc.get_body().first_child().first_child().first_child(),
model.Span
)

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

0 comments on commit 3965486

Please sign in to comment.