diff --git a/src/main/python/ttconv/vtt/writer.py b/src/main/python/ttconv/vtt/writer.py index 2a079e61..73271859 100644 --- a/src/main/python/ttconv/vtt/writer.py +++ b/src/main/python/ttconv/vtt/writer.py @@ -104,7 +104,38 @@ def __init__(self, config: VTTWriterConfiguration): ) def process_inline_element(self, element: model.ContentElement, begin: Fraction, end: Optional[Fraction]): - """Converts inline element (span and br) to VTT content""" + """Converts inline element (ruby, rb, rp, rt, rbc, rtc, span and br) to VTT content""" + + if isinstance(element, model.Ruby): + self._paragraphs[-1].append_text('') + rtc = False + for elem in list(element): + if isinstance(elem, model.Rtc): + if rtc: continue + rtc = True + self.process_inline_element(elem, begin, end) + self._paragraphs[-1].append_text('') + + if isinstance(element, model.Rbc): + for elem in list(element): + self.process_inline_element(elem, begin, end) + + if isinstance(element, model.Rtc): + for elem in list(element): + self.process_inline_element(elem, begin, end) + + if isinstance(element, model.Rb): + for elem in list(element): + self.process_inline_element(elem, begin, end) + + if isinstance(element, model.Rp): + pass + + if isinstance(element, model.Rt): + self._paragraphs[-1].append_text('') + for elem in list(element): + self.process_inline_element(elem, begin, end) + self._paragraphs[-1].append_text('') if isinstance(element, model.Span): is_bold = style.is_element_bold(element) diff --git a/src/test/python/test_vtt_writer.py b/src/test/python/test_vtt_writer.py index 8aec6d67..ab0e514a 100644 --- a/src/test/python/test_vtt_writer.py +++ b/src/test/python/test_vtt_writer.py @@ -150,6 +150,53 @@ def test_position(self): vtt_from_model = vtt_writer.from_model(model, config) self.assertEqual(expected_vtt, vtt_from_model) + def test_ruby(self): + ttml_doc_str = """ + + + + + + + +
+

+ basetext +

+

+ base(text) +

+

+ + base + text1 + text2 + +

+
+ +
""" + + expected_vtt="""WEBVTT + +1 +00:00:00.000 --> 00:00:01.000 +basetext + +2 +00:00:01.000 --> 00:00:02.000 +basetext + +3 +00:00:02.000 --> 00:00:03.000 +basetext1 +""" + + model = imsc_reader.to_model(et.ElementTree(et.fromstring(ttml_doc_str))) + config = VTTWriterConfiguration() + vtt_from_model = vtt_writer.from_model(model, config) + self.assertEqual(expected_vtt, vtt_from_model) + def test_align(self): ttml_doc_str = """