Ejemplo n.º 1
0
    def __init__(self, stream, encoding):
        HtmlPrinter.__init__(self, stream, encoding)
        self._level = 0

        # indenting control variables
        self._isInline = [1]  # prevent newline before first element
        self._inNoIndent = [0]
        self._indentForbidden = 0
        self._indentEndTag = False
        return
Ejemplo n.º 2
0
    def __init__(self, stream, encoding):
        HtmlPrinter.__init__(self, stream, encoding)
        self._level = 0

        # indenting control variables
        self._isInline = [1]  # prevent newline before first element
        self._inNoIndent = [0]
        self._indentForbidden = 0
        self._indentEndTag = False
        return
Ejemplo n.º 3
0
    def comment(self, data):
        if self._inElement:
            self.writeAscii('>')
            self._inElement = False

        # OK to indent end-tag
        self._indentEndTag = True

        # try to indent
        if not self._isInline[-1] and not self._indentForbidden:
            self.writeAscii('\n' + (self.indent * self._level))
        HtmlPrinter.comment(self, data)
        return
Ejemplo n.º 4
0
    def processingInstruction(self, target, data):
        if self._inElement:
            self.writeAscii('>')
            self._inElement = False

        # OK to indent end-tag
        self._indentEndTag = True

        # try to indent
        if not self._isInline[-1] and not self._indentForbidden:
            self.writeAscii('\n' + (self.indent * self._level))
        HtmlPrinter.processingInstruction(self, target, data)
        return
Ejemplo n.º 5
0
    def comment(self, data):
        if self._inElement:
            self.writeAscii('>')
            self._inElement = False

        # OK to indent end-tag
        self._indentEndTag = True

        # try to indent
        if not self._isInline[-1] and not self._indentForbidden:
            self.writeAscii('\n' + (self.indent * self._level))
        HtmlPrinter.comment(self, data)
        return
Ejemplo n.º 6
0
    def processingInstruction(self, target, data):
        if self._inElement:
            self.writeAscii('>')
            self._inElement = False

        # OK to indent end-tag
        self._indentEndTag = True

        # try to indent
        if not self._isInline[-1] and not self._indentForbidden:
            self.writeAscii('\n' + (self.indent * self._level))
        HtmlPrinter.processingInstruction(self, target, data)
        return
Ejemplo n.º 7
0
    def endElement(self, namespaceUri, tagName):
        # Undo changes to indenting rules for this element
        self._level -= 1
        inline = self._isInline.pop()

        if self._inElement:
            # An empty non-null namespace element (use XML short form)
            self.writeAscii('/>')
            self._inElement = False
        else:
            if not inline and not self._indentForbidden and self._indentEndTag:
                self.writeAscii('\n' + (self.indent * self._level))

            HtmlPrinter.endElement(self, namespaceUri, tagName)

        self._indentForbidden -= self._inNoIndent.pop()
        self._indentEndTag = not inline
        return
Ejemplo n.º 8
0
    def endElement(self, namespaceUri, tagName):
        # Undo changes to indenting rules for this element
        self._level -= 1
        inline = self._isInline.pop()

        if self._inElement:
            # An empty non-null namespace element (use XML short form)
            self.writeAscii('/>')
            self._inElement = False
        else:
            if not inline and not self._indentForbidden and self._indentEndTag:
                self.writeAscii('\n' + (self.indent * self._level))

            HtmlPrinter.endElement(self, namespaceUri, tagName)

        self._indentForbidden -= self._inNoIndent.pop()
        self._indentEndTag = not inline
        return
Ejemplo n.º 9
0
    def startElement(self, namespaceUri, tagName, namespaces, attributes):
        if self._inElement:
            self.writeAscii('>')
            self._inElement = False

        # Create the lookup key for the various lookup tables
        key = (namespaceUri, tagName.lower())

        # Get the inline flag for this element
        inline = key in self.inlineElements

        if not inline and not self._isInline[-1] and not self._indentForbidden:
            self.writeAscii('\n' + (self.indent * self._level))

        HtmlPrinter.startElement(self, namespaceUri, tagName, namespaces,
                                 attributes)

        # Setup indenting rules for this element
        self._isInline.append(inline)
        self._inNoIndent.append(key in self.noIndentElements)
        self._indentForbidden += self._inNoIndent[-1]
        self._level += 1
        self._indentEndTag = False
        return
Ejemplo n.º 10
0
    def startElement(self, namespaceUri, tagName, namespaces, attributes):
        if self._inElement:
            self.writeAscii('>')
            self._inElement = False

        # Create the lookup key for the various lookup tables
        key = (namespaceUri, tagName.lower())

        # Get the inline flag for this element
        inline = key in self.inlineElements

        if not inline and not self._isInline[-1] and not self._indentForbidden:
            self.writeAscii('\n' + (self.indent * self._level))

        HtmlPrinter.startElement(self, namespaceUri, tagName, namespaces,
                                 attributes)

        # Setup indenting rules for this element
        self._isInline.append(inline)
        self._inNoIndent.append(key in self.noIndentElements)
        self._indentForbidden += self._inNoIndent[-1]
        self._level += 1
        self._indentEndTag = False
        return