def formatBlock(self, block, state):
        """Apply transformation to given block."""
        blockFormat = QTextBlockFormat()

        if state == State.BLOCKQUOTE_LINE:
            # Number of tabs
            n = block.text().indexOf(QRegExp(r'[^\t]'), 0)
            blockFormat.setIndent(0)
            blockFormat.setTextIndent(-self.tabStopWidth * n)
            blockFormat.setLeftMargin(self.tabStopWidth * n)
            # blockFormat.setRightMargin(self.editor.contentsRect().width()
            # - self.editor.lineNumberAreaWidth()
            # - fm.width("X") * self.editor.LimitLine
            # + self.editor.tabStopWidth())
            blockFormat.setAlignment(Qt.AlignJustify)
            if self.name == "Default":
                blockFormat.setTopMargin(5)
                blockFormat.setBottomMargin(5)
        elif state == State.HEADER_LINE:
            blockFormat.setBackground(QColor("#EEEEEE"))
        elif state in State.LIST:
            data = blockUserData.getUserData(block)
            if str(data.listSymbol()) in "+-":
                blockFormat.setBackground(QColor("#EEFFEE"))
            else:
                blockFormat.setBackground(QColor("#EEEEFA"))
            n = blockUserData.getUserData(block).leadingSpaces() + 1

            f = QFontMetrics(QFont(self.defaultFontFamily,
                                   self._defaultCharFormat.font().pointSize()))
            fm = f.width(" " * n +
                         blockUserData.getUserData(block).listSymbol())
            blockFormat.setTextIndent(-fm)
            blockFormat.setLeftMargin(fm)
            if blockUserData.getUserState(block) == State.LIST_BEGINS and \
                            self.name == "Default":
                blockFormat.setTopMargin(5)
        return blockFormat