コード例 #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]
コード例 #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
コード例 #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
コード例 #4
0
ファイル: test_dom.py プロジェクト: su27/draftjs_exporter
 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')