Exemplo n.º 1
0
    def parse(self, stream=None, inline=False, enable_escaping=False):
        """
        Parse an existing stream or the current `raw` document,
        apply node-filters and return a node-tree.

        :param stream:  An existing stream. If `None` the `raw` attribute
                        is processed into a `TokenStream`.
        :param inline:  If `True` only child-nodes are returned and no
                        `Document` node as the top level one.
        :return:        A node-tree that represents the finished document
                        in an abstract form.
        """
        if stream is None:
            stream = self.tokenize(enable_escaping=enable_escaping)

        # create the node-tree
        document = events.emit_ovr("define-document-node")()

        while not stream.eof:
            node = self.dispatch_node(stream)
            if node is not None:
                document.children.append(node)
            else:
                stream.next()

        # apply node-filters
        ctx = Context(self, enable_escaping)
        for callback in events.iter_callbacks("process-doc-tree"):
            ret = callback(document, ctx)
            if ret is not None:
                document = ret

        if inline:
            return document.children
        return document
Exemplo n.º 2
0
    def parse(self, stream=None, inline=False, enable_escaping=False):
        """
        Parse an existing stream or the current `raw` document,
        apply node-filters and return a node-tree.

        :param stream:  An existing stream. If `None` the `raw` attribute
                        is processed into a `TokenStream`.
        :param inline:  If `True` only child-nodes are returned and no
                        `Document` node as the top level one.
        :return:        A node-tree that represents the finished document
                        in an abstract form.
        """
        if stream is None:
            stream = self.tokenize(enable_escaping=enable_escaping)

        # create the node-tree
        document = events.emit_ovr('define-document-node')()

        while not stream.eof:
            node = self.dispatch_node(stream)
            if node is not None:
                document.children.append(node)
            else:
                stream.next()

        # apply node-filters
        ctx = Context(self, enable_escaping)
        for callback in events.iter_callbacks('process-doc-tree'):
            ret = callback(document, ctx)
            if ret is not None:
                document = ret

        if inline:
            return document.children
        return document
Exemplo n.º 3
0
 def _process_special_events(self):
     # raw_directive
     self.raw_directive = rw = events.emit_ovr("define-raw-directive")(self)
     # and the raw directive name
     self.raw_name = rw.name
Exemplo n.º 4
0
 def _process_special_events(self):
     # raw_directive
     self.raw_directive = rw = events.emit_ovr('define-raw-directive')(self)
     # and the raw directive name
     self.raw_name = rw.name