예제 #1
0
    def prepare_content_tree(self):
        """
        Prepares this node for further processing.
        """
        for node_id in self._child_nodes:
            node = node_store.in_scope(node_id)

            node.prepare_content_tree()

            node_store.out_scope(node)
예제 #2
0
    def prepare_content_tree(self):
        """
        Method which checks if all child nodes is instance of sdoc.sdoc2.node.ItemNode.ItemNode.
        """
        for node_id in self._child_nodes:
            node = node_store.in_scope(node_id)

            if not isinstance(node, ItemNode):
                raise RuntimeError("Node: id:%s, %s is not instance of 'ItemNode'" % (str(node.id), node.name))

            node_store.out_scope(node)
예제 #3
0
    def prepare_content_tree(self):
        """
        Method which checks if all child nodes is instance of sdoc.sdoc2.node.ItemNode.ItemNode.
        """
        for node_id in self._child_nodes:
            node = node_store.in_scope(node_id)

            if not isinstance(node, ItemNode):
                raise RuntimeError(
                    "Node: id:%s, %s is not instance of 'ItemNode'" %
                    (str(node.id), node.name))

            node_store.out_scope(node)
예제 #4
0
    def print_info(self, level):
        """
        Temp function for development.

        :param int level: the level of block commands.
        """
        print("%s%4d %s" % (' ' * 4 * level, self.id, self.name))
        for node_id in self._child_nodes:
            node = node_store.in_scope(node_id)

            node.print_info(level + 1)

            node_store.out_scope(node)
예제 #5
0
    def prepare_content_tree(self):
        """
        Method which checks if all child nodes is phrasing.
        """
        for node_id in self._child_nodes:
            node = node_store.in_scope(node_id)

            if isinstance(node, TextNode):
                node.prune_whitespace()

            # if not node.is_phrasing():
            #    raise RuntimeError("Node: id:%s, %s is not phrasing" % (str(node.id), node.name))

            node_store.out_scope(node)
예제 #6
0
    def prepare_content_tree(self):
        """
        Method which checks if all child nodes is phrasing.
        """
        for node_id in self._child_nodes:
            node = node_store.in_scope(node_id)

            if isinstance(node, TextNode):
                node.prune_whitespace()

            # if not node.is_phrasing():
            #    raise RuntimeError("Node: id:%s, %s is not phrasing" % (str(node.id), node.name))

            node_store.out_scope(node)
예제 #7
0
    def generate(self, node, file):
        """
        Generates the representation of a node is the requested output format.

        :param sdoc.sdoc2.node.Node.Node node: The node for which the output must be generated.
        :param file file: The output file.
        """

        for node_id in node._child_nodes:  # @todo fix access
            child_node = node_store.in_scope(node_id)

            decorator = node_store.create_format_decorator(child_node.get_command(), self)
            decorator.generate(child_node, file)

            node_store.out_scope(child_node)
예제 #8
0
    def prune_whitespace(self):
        """
        Removes spaces from end of a paragraph.
        """
        first = self._child_nodes[0]
        last = self._child_nodes[-1]

        for node_id in self._child_nodes:
            node = node_store.in_scope(node_id)

            if isinstance(node, TextNode):
                if node.id == first:
                    node.prune_whitespace(leading=True)
                if node.id == last:
                    node.prune_whitespace(trailing=True)
                if node.id != last and node.id != first:
                    node.prune_whitespace()

            node_store.out_scope(node)
예제 #9
0
    def prune_whitespace(self):
        """
        Removes spaces from end of a paragraph.
        """
        first = self._child_nodes[0]
        last = self._child_nodes[-1]

        for node_id in self._child_nodes:
            node = node_store.in_scope(node_id)

            if isinstance(node, TextNode):
                if node.id == first:
                    node.prune_whitespace(leading=True)
                if node.id == last:
                    node.prune_whitespace(trailing=True)
                if node.id != last and node.id != first:
                    node.prune_whitespace()

            node_store.out_scope(node)
예제 #10
0
    def split_text_nodes(self):
        """
        Replaces single text nodes that contains a paragraph separator (i.e. a double new line) with multiple text nodes
        without paragraph separator.
        """
        new_child_nodes = []

        for node_id in self._child_nodes:
            node = node_store.in_scope(node_id)

            if isinstance(node, TextNode):
                list_ids = node.split_by_paragraph()
                for ids in list_ids:
                    new_child_nodes.append(ids)
            else:
                new_child_nodes.append(node.id)

            node_store.out_scope(node)

        self._child_nodes = new_child_nodes
예제 #11
0
    def split_text_nodes(self):
        """
        Replaces single text nodes that contains a paragraph separator (i.e. a double new line) with multiple text nodes
        without paragraph separator.
        """
        new_child_nodes = []

        for node_id in self._child_nodes:
            node = node_store.in_scope(node_id)

            if isinstance(node, TextNode):
                list_ids = node.split_by_paragraph()
                for ids in list_ids:
                    new_child_nodes.append(ids)
            else:
                new_child_nodes.append(node.id)

            node_store.out_scope(node)

        self._child_nodes = new_child_nodes
예제 #12
0
    def create_paragraphs(self):
        """
        Create paragraph nodes.

        A paragraph consists of phrasing nodes only. Each continuous slice of phrasing child nodes is move to a
        paragraph node.
        """
        new_child_nodes = []
        paragraph_node = None

        for node_id in self._child_nodes:
            node = node_store.in_scope(node_id)

            if node.is_phrasing():
                if not paragraph_node:
                    paragraph_node = sdoc.sdoc2.node_store.create_inline_node(
                        'paragraph')
                    new_child_nodes.append(paragraph_node.id)

                paragraph_node.append_child_node(node)
            else:
                if paragraph_node:
                    paragraph_node.prune_whitespace()
                    sdoc.sdoc2.node_store.store_node(paragraph_node)
                    paragraph_node = None

                # End paragraph nodes are created temporary to separate paragraphs in a flat list of (text) node. There
                # role ae replaced by the content hierarchy now. So, we must no store end paragraph nodes.
                if not isinstance(node, EndParagraphNode):
                    new_child_nodes.append(node.id)

            node_store.out_scope(node)

        if paragraph_node:
            paragraph_node.prune_whitespace()
            sdoc.sdoc2.node_store.store_node(paragraph_node)
            # paragraph_node = None

        # Setting child nodes.
        self._child_nodes = new_child_nodes
예제 #13
0
    def create_paragraphs(self):
        """
        Create paragraph nodes.

        A paragraph consists of phrasing nodes only. Each continuous slice of phrasing child nodes is move to a
        paragraph node.
        """
        new_child_nodes = []
        paragraph_node = None

        for node_id in self._child_nodes:
            node = node_store.in_scope(node_id)

            if node.is_phrasing():
                if not paragraph_node:
                    paragraph_node = sdoc.sdoc2.node_store.create_inline_node('paragraph')
                    new_child_nodes.append(paragraph_node.id)

                paragraph_node.append_child_node(node)
            else:
                if paragraph_node:
                    paragraph_node.prune_whitespace()
                    sdoc.sdoc2.node_store.store_node(paragraph_node)
                    paragraph_node = None

                # End paragraph nodes are created temporary to separate paragraphs in a flat list of (text) node. There
                # role ae replaced by the content hierarchy now. So, we must no store end paragraph nodes.
                if not isinstance(node, EndParagraphNode):
                    new_child_nodes.append(node.id)

            node_store.out_scope(node)

        if paragraph_node:
            paragraph_node.prune_whitespace()
            sdoc.sdoc2.node_store.store_node(paragraph_node)
            # paragraph_node = None

        # Setting child nodes.
        self._child_nodes = new_child_nodes