示例#1
0
    def _process_content(self, nodes, special):
        """Parse the directive content and place it in the appropiate nodes.

        Parameters
        ----------
        nodes, special: the result of run_reference.

        Returns
        -------
        nodes: new list of nodes
        """
        uccontent = special.get("antidox_usercontent")

        assert nodes if uccontent else True

        # If there is a antidox_usercontent node, it should be REPLACED by
        # the user content, but if not, we must find a default placement node
        # and NEST the user content UNDER that node.
        if uccontent:
            # make a temporary container
            content_container = Element()
        elif not nodes:
            # This may give weird unexpected results when children are added.
            content_container = paragraph()
            nodes = [content_container]
        else:
            child_index = nodes[0].first_child_matching_class(
                addnodes.desc_content)
            content_container = (nodes[0][child_index]
                                 if child_index is not None else nodes[-1])

        if self.content:
            nested_parse_with_titles(self.state, self.content,
                                     content_container)

        if uccontent:
            # handle the case where antidox_usercontent is at the top level
            if uccontent.parent:
                uccontent.replace_self(content_container.children)
            else:
                uc_index = nodes.index(uccontent)
                nodes[uc_index:uc_index+1] = content_container.children
            assert nodes if self.content else True

        return nodes