def add_node(self, element, text): if self.is_unstyled(): child = DOM.create_text_node(text) DOM.append_child(element, child) else: tags = self.get_style_tags() child = element # Nest the tags. # Set the text and style attribute (if any) on the deepest node. for tag in tags: new_child = DOM.create_element(tag) DOM.append_child(child, new_child) child = new_child style_value = self.get_style_value() if style_value: DOM.set_attribute(child, 'style', style_value) class_value = self.get_class_value() if class_value: DOM.set_attribute(child, 'class', class_value) DOM.set_text_content(child, text) return child
def test_set_text_content(self): elt = DOM.create_element('p') DOM.set_text_content(elt, 'Test test') self.assertEqual(DOM.get_text_content(elt), 'Test test')