Ejemplo n.º 1
0
    def create_nodes(self, text, block=None, entity_stack=None):
        if entity_stack:
            text_children = [DOM.create_text_node(text)]
        else:
            text_children = get_decorations(self.composite_decorators, text,
                                            block)

        if self.is_unstyled():
            return list(text_children)

        else:
            tags = self.get_style_tags()
            node = DOM.create_element(tags[0])
            child = node

            # Nest the tags.
            # Set the text and style attribute (if any) on the deepest node.
            for tag in tags[1:]:
                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)
            for text_child in text_children:
                DOM.append_child(child, text_child)

            return [node]
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
    def create_node(self, text):
        text_lines = self.replace_linebreaks(text)

        if self.is_unstyled():
            node = text_lines
        else:
            tags = self.get_style_tags()
            node = DOM.create_element(tags[0])
            child = node

            # Nest the tags.
            # Set the text and style attribute (if any) on the deepest node.
            for tag in tags[1:]:
                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)

            DOM.append_child(child, text_lines)

        return node
Ejemplo n.º 4
0
 def test_set_attribute(self):
     elt = DOM.create_element('a')
     DOM.set_attribute(elt, 'href', 'http://example.com')
     self.assertEqual(elt.get('href'), 'http://example.com')