Exemple #1
0
 def from_xml(
   parent_ctx: typing.Optional[TTMLElement.ParsingContext],
   xml_elem: et.Element
 ) -> typing.Optional[RubyElement.ParsingContext]:
   ruby_ctx = RubyElement.ParsingContext(RubyElement, parent_ctx, model.Ruby(parent_ctx.doc))
   ruby_ctx.process(parent_ctx, xml_elem)
   return ruby_ctx
Exemple #2
0
    def test_push_child(self):

        p = model.P()

        p.push_child(model.Br())

        p.push_child(model.Span())

        p.push_child(model.Ruby())

        with self.assertRaises(TypeError):
            p.push_child(model.Text())
Exemple #3
0
    def test_remove_child(self):

        r = model.Ruby()

        c1 = model.Rb()

        c2 = model.Rt()

        r.push_children([c1, c2])

        with self.assertRaises(RuntimeError):
            c1.remove()

        with self.assertRaises(RuntimeError):
            r.remove_child(c1)
Exemple #4
0
    def test_push_children(self):

        r = model.Ruby()

        r.push_children([model.Rb(), model.Rt()])

        r.remove_children()

        r.push_children([model.Rb(), model.Rp(), model.Rt(), model.Rp()])

        r.remove_children()

        r.push_children([model.Rbc(), model.Rtc()])

        r.remove_children()

        r.push_children([model.Rbc(), model.Rtc(), model.Rtc()])

        with self.assertRaises(RuntimeError):
            r.push_children([model.Rb(), model.Rt()])
Exemple #5
0
    def process(context, inherited_space, inherited_lang, ttml_element):

        element = model.Ruby(context.doc)

        # process attributes

        element.set_space(
            XMLSpaceAttribute.extract(ttml_element) or inherited_space)

        element.set_lang(
            XMLLangAttribute.extract(ttml_element) or inherited_lang)

        ContentElement.process_region_property(context, ttml_element, element)

        ContentElement.process_style_properties(context, ttml_element, element)

        # process children elements

        children = []

        for ttml_child_element in ttml_element:
            child_element = ContentElement.process(context,
                                                   element.get_space(),
                                                   element.get_lang(),
                                                   ttml_child_element)

            if child_element is not None:

                children.append(child_element)

        try:

            element.push_children(children)

            return element

        except (RuntimeError, TypeError):

            LOGGER.error("Malformed ruby element")

            return None
Exemple #6
0
    def test_push_child(self):

        r = model.Ruby()

        with self.assertRaises(RuntimeError):
            r.push_child(model.P())