Beispiel #1
0
    def run(self):
        node = nodes.Element()
        node.document = self.state.document
        jinja_context_name = self.arguments[0]
        template_filename = self.options.get("file")
        cxt = self.app.config.jinja_contexts[jinja_context_name]
        cxt["options"] = {"header_char": self.options.get("header_char")}

        if template_filename:
            reference_uri = directives.uri(template_filename)
            template_path = urllib.url2pathname(reference_uri)
            encoded_path = template_path.encode(sys.getfilesystemencoding())
            imagerealpath = os.path.abspath(encoded_path)
            with open(imagerealpath) as f:
                tpl = Template(f.read())
        else:
            tpl = Template("\n".join(self.content))
        new_content = tpl.render(**cxt)
        # transform the text content into a string_list that the nested_parse
        # can use:
        new_content = StringList(new_content.split("\n"))
        self.state.nested_parse(new_content,
                                self.content_offset,
                                node,
                                match_titles=1)
        return node.children
Beispiel #2
0
    def run(self):
        node = nodes.Element()
        node.document = self.state.document
        jinja_context_name = self.arguments[0]
        template_filename = self.options.get("file")
        cxt = self.app.config.jinja_contexts[jinja_context_name]
        cxt["options"] = {
            "header_char": self.options.get("header_char")
        }

        if template_filename:
            reference_uri = directives.uri(template_filename)
            template_path = urllib.url2pathname(reference_uri)
            encoded_path = template_path.encode(sys.getfilesystemencoding())
            imagerealpath = os.path.abspath(encoded_path)
            with open(imagerealpath) as f:
                tpl = Template(f.read())
        else:
            tpl = Template("\n".join(self.content))
        new_content = tpl.render(**cxt)
        # transform the text content into a string_list that the nested_parse
        # can use:
        new_content = StringList(new_content.split("\n"))
        self.state.nested_parse(new_content, self.content_offset,
                                node, match_titles=1)
        return node.children