Exemplo n.º 1
0
    def highlightBlock(self, text):
        for pattern, format in self.highlightingRules:
            expression = QRegExp(pattern)
            index = expression.indexIn(text)
            while index >= 0:
                length = expression.matchedLength()
                self.setFormat(index, length, format)
                index = expression.indexIn(text, index + length)

        self.setCurrentBlockState(0)

        startIndex = 0
        if self.previousBlockState() != 1:
            startIndex = self.commentStartExpression.indexIn(text)

        while startIndex >= 0:
            endIndex = self.commentEndExpression.indexIn(text, startIndex)

            if endIndex == -1:
                self.setCurrentBlockState(1)
                commentLength = len(text) - startIndex
            else:
                commentLength = endIndex - startIndex + self.commentEndExpression.matchedLength(
                )

            self.setFormat(startIndex, commentLength,
                           self.multiLineCommentFormat)
            startIndex = self.commentStartExpression.indexIn(
                text, startIndex + commentLength)
Exemplo n.º 2
0
 def databaseHighlighting(self, text):
     for pattern, format_v in self.highlightingRules:
         expression = QRegExp(pattern)
         index = expression.indexIn(text)
         while index >= 0:
             length = expression.matchedLength()
             self.setFormat(index, length, format_v)
             index = expression.indexIn(text, index + length)
Exemplo n.º 3
0
 def highlightBlock(self, text):
     for pattern, _format in self.highlighting_rules:
         expression = QRegExp(pattern)
         index = expression.indexIn(text)
         while index >= 0:
             length = expression.matchedLength()
             self.setFormat(index, length, _format)
             index = expression.indexIn(text, index + length)
Exemplo n.º 4
0
 def highlightBlock(self, text):
     for pattern, n, format in self.rules:
         exp = QRegExp(pattern)
         index = exp.indexIn(text)
         while index >= 0:
             length = exp.matchedLength()
             self.setFormat(index, length, format)
             index = exp.indexIn(text, index + length)
Exemplo n.º 5
0
class Highlighter(QSyntaxHighlighter):
    def __init__(self, parent=None):
        super(Highlighter, self).__init__(parent)

        keywordFormat = QTextCharFormat()
        keywordFormat.setForeground(Qt.darkBlue)
        keywordFormat.setFontWeight(QFont.Bold)

        keywordPatterns = [
            "\\bimport\\b", "\\bcomponent\\b", "\\bcommunications\\b",
            "\\bpublishes\\b", "\\bimplements\\b", "\\bsubscribesTo\\b",
            "\\brequires\\b", "\\blanguage\\b", "\\bgui\\b", "\\boptions\\b",
            "\\binnermodelviewer\\b", "\\bstateMachine\\b", "\\bmodules\\b",
            "\\bagmagent\\b"
        ]

        self.highlightingRules = [(QRegExp(pattern), keywordFormat)
                                  for pattern in keywordPatterns]

        self.multiLineCommentFormat = QTextCharFormat()
        self.multiLineCommentFormat.setForeground(Qt.red)

        self.commentStartExpression = QRegExp("/\\*")
        self.commentEndExpression = QRegExp("\\*/")

    def highlightBlock(self, text):
        for pattern, format in self.highlightingRules:
            expression = QRegExp(pattern)
            index = expression.indexIn(text)
            while index >= 0:
                length = expression.matchedLength()
                self.setFormat(index, length, format)
                index = expression.indexIn(text, index + length)

        self.setCurrentBlockState(0)

        startIndex = 0
        if self.previousBlockState() != 1:
            startIndex = self.commentStartExpression.indexIn(text)

        while startIndex >= 0:
            endIndex = self.commentEndExpression.indexIn(text, startIndex)

            if endIndex == -1:
                self.setCurrentBlockState(1)
                commentLength = len(text) - startIndex
            else:
                commentLength = endIndex - startIndex + self.commentEndExpression.matchedLength(
                )

            self.setFormat(startIndex, commentLength,
                           self.multiLineCommentFormat)
            startIndex = self.commentStartExpression.indexIn(
                text, startIndex + commentLength)
Exemplo n.º 6
0
class SydTableSortFilterProxyModel(QtCore.QSortFilterProxyModel):

    def __init__(self, header):
        super(SydTableSortFilterProxyModel, self).__init__()
        self._header = header
        self._filters = {}
        self._global_filter = \
            QRegExp('', Qt.CaseInsensitive, QRegExp.FixedString)

    def filterAcceptsRow(self, source_row, source_parent):
        # column filters
        for key, regex in self._filters.items():
            ix = self.sourceModel().index(source_row, key, source_parent)
            if ix.isValid():
                text = self.sourceModel().data(ix, Qt.DisplayRole)
                if regex.indexIn(str(text)) == -1:
                    return False
        # global filter
        for key in range(len(self._header._editors)):
            ix = self.sourceModel().index(source_row, key, source_parent)
            text = self.sourceModel().data(ix, Qt.DisplayRole)
            if self._global_filter.indexIn(str(text)) != -1:
                return True
        return False

    def set_filter_by_column(self, regex, column):
        self._filters[column] = regex
        self.invalidateFilter()

    def set_global_filter(self, text):
        r = QRegExp(text,
                    Qt.CaseInsensitive,
                    QRegExp.FixedString)
        self._global_filter = r
        self.invalidateFilter()
Exemplo n.º 7
0
 def find_with_pattern(self, pattern):
     self.setUndoRedoEnabled(False)
     self.clear_format()
     if pattern == "":
         return
     cursor = self.textCursor()
     regex = QRegExp(pattern)
     pos = 0
     index = regex.indexIn(self.toPlainText(), pos)
     while index != -1:
         cursor.setPosition(index)
         cursor.movePosition(QTextCursor.EndOfWord, QTextCursor.KeepAnchor,
                             1)
         cursor.mergeCharFormat(self.findHighlightFormat)
         pos = index + regex.matchedLength()
         index = regex.indexIn(self.toPlainText(), pos)
     self.setUndoRedoEnabled(True)
Exemplo n.º 8
0
 def filterAcceptsRow(self, source_row, source_parent):
     for column, expresion in self.filters.items():
         text = self.sourceModel().index(source_row, column,
                                         source_parent).data()
         regex = QRegExp(expresion, Qt.CaseInsensitive, QRegExp.RegExp)
         if regex.indexIn(text) == -1:
             return False
     return True
Exemplo n.º 9
0
    def highlightBlock(self, text):
        # for pattern, n, format in self.rules:
        #     exp = QRegExp(pattern)
        #     index = exp.indexIn(text)
        #     while index >= 0:
        #         length = exp.matchedLength()
        #         # length = pattern.cap(n).lenght()
        #         self.setFormat(index, length, format)
        #         index = exp.indexIn(text, index + length)
        for pattern, format in self.rules:
            exp = QRegExp(pattern)
            index = exp.indexIn(text)
            while index >= 0:
                length = exp.matchedLength()
                # length = pattern.cap(n).lenght()
                self.setFormat(index, length, format)
                index = exp.indexIn(text, index + length)

        self.setCurrentBlockState(0)

        start_index = 0
        if self.previousBlockState() != 1:
            # start_index = exp.indexIn(text)
            start_index = self.commentStartExpression.indexIn(text)
        while start_index >= 0:
            # rex = QRegularExpression(self.multiline_comment_end)
            # match = rex.match(text, start_index)
            # end_index = match.capturedStart()
            end_index = self.commentEndExpression.indexIn(text, start_index)
            if end_index == -1:
                self.setCurrentBlockState(1)
                comment_length = len(text) - start_index
            else:
                # comment_length = end_index - start_index + match.capturedLength()
                comment_length = end_index - start_index + self.commentEndExpression.matchedLength()
            self.setFormat(start_index, comment_length, self.formater.stilovi['comment'])
            start_index = self.commentStartExpression.indexIn(text, start_index + comment_length)
    def filterAcceptsRow(self, sourceRow, sourceParent):
        sourceModel = self.sourceModel()
        filter_str = self.filterRegExp().pattern()
        components = filter_str.split(',')

        #any unspecified columns at the end are assumed to match
        accept = True
        col = 0
        while accept and col < len(components):
            index = sourceModel.index(sourceRow, col, sourceParent)
            regex = QRegExp('^' + components[col],
                            cs=Qt.CaseSensitivity.CaseInsensitive)

            #convert to a string to simplify regexp matching
            data_item = str(sourceModel.data(index))
            accept = accept and regex.indexIn(data_item) != -1
            col += 1

        return accept
Exemplo n.º 11
0
class CSyntax(QSyntaxHighlighter):
    keywords_c = ['long', 'unsigned', 'short', 'int', 'double', 'float', 'char', 'struct', 'typedef', 'for', 'while',
                'union', 'return', 'if', 'else', 'break', 'continue', 'const', 'void', 'switch', 'case', 'default']
    functions = ['printf', 'scanf', 'malloc', 'calloc', 'memset', 'sizeof', 'free',
                 'getc', 'gets', 'getchar', 'puts', 'putchar', 'clearerr', 'fopen', 'fclose', 'getw',
                 'putw', 'fgetc', 'putc', 'fputc', 'fgets', 'fputs', 'feof', 'fprintf', 'fscanf',
                 'fgetchar', 'fputchar', 'fseek', 'SEEK_SET', 'SEEK_CUR', 'SEEK_END', 'ftell', 'rewind',
                 'sprintf', 'sscanf', 'remove', 'fflush', 'realloc', 'abs', 'div', 'abort', 'exit', 'system',
                 'atoi', 'atol', 'atof', 'strtod', 'strtol', 'getenv', 'setenv', 'putenv', 'perror', 'rand', 'delay']

    def __init__(self, dokument):
        super(CSyntax, self).__init__(dokument)
        self.rules = []
        self.formater = Formater()
        # self.rules += [(r'(\/\*[^(\*\/)]*\*\/)', 0, self.formater.stilovi['comment'])]
        self.rules += [(r'\b%s\b' % w, self.formater.stilovi['keyword']) for w in CSyntax.keywords_c]
        # self.rules += [(r'\b%s\b' % w, 0, self.formater.stilovi['declarations']) for w in CSyntax.functions]
        self.rules += [(QRegExp(r'\b(?!(?:if|switch|while|void|for)[\s*|(])\b[A-Za-z0-9\_]+\s*(?=\([^\)]*\)\s*)'),
                        self.formater.stilovi['declarations'])]
        self.rules += [(QRegExp(r'#[^\n]*'), self.formater.stilovi['string_c'])]
        self.rules += [(QRegExp(r"\".*\""), self.formater.stilovi['string'])]
        self.rules += [(QRegExp(r"\'.?\'"), self.formater.stilovi['string'])]
        # self.multiline_comment_start = r'/\*.*'
        # self.multiline_comment_end = r'[^\*/]*\*/'
        # self.multiline_comment_start = r'/\\*'
        # self.multiline_comment_end = r'\\*/'
        self.multiLineCommentFormat = QTextCharFormat()
        self.multiLineCommentFormat.setForeground(Qt.red)
        self.commentStartExpression = QRegExp("/\\*")
        self.commentEndExpression = QRegExp("\\*/")
        self.rules += [(QRegExp(r'//[^\n]*'), self.formater.stilovi['comment_c'])]

        # self.rules = [(QRegExp(pat), index, fmt) for (pat, index, fmt) in self.rules]

    def highlightBlock(self, text):
        # for pattern, n, format in self.rules:
        #     exp = QRegExp(pattern)
        #     index = exp.indexIn(text)
        #     while index >= 0:
        #         length = exp.matchedLength()
        #         # length = pattern.cap(n).lenght()
        #         self.setFormat(index, length, format)
        #         index = exp.indexIn(text, index + length)
        for pattern, format in self.rules:
            exp = QRegExp(pattern)
            index = exp.indexIn(text)
            while index >= 0:
                length = exp.matchedLength()
                # length = pattern.cap(n).lenght()
                self.setFormat(index, length, format)
                index = exp.indexIn(text, index + length)

        self.setCurrentBlockState(0)

        start_index = 0
        if self.previousBlockState() != 1:
            # start_index = exp.indexIn(text)
            start_index = self.commentStartExpression.indexIn(text)
        while start_index >= 0:
            # rex = QRegularExpression(self.multiline_comment_end)
            # match = rex.match(text, start_index)
            # end_index = match.capturedStart()
            end_index = self.commentEndExpression.indexIn(text, start_index)
            if end_index == -1:
                self.setCurrentBlockState(1)
                comment_length = len(text) - start_index
            else:
                # comment_length = end_index - start_index + match.capturedLength()
                comment_length = end_index - start_index + self.commentEndExpression.matchedLength()
            self.setFormat(start_index, comment_length, self.formater.stilovi['comment'])
            start_index = self.commentStartExpression.indexIn(text, start_index + comment_length)
Exemplo n.º 12
0
    def highlightBlock(self, text):
        self.setCurrentBlockState(States.NONE.value)

        # TAG
        start_index = 0
        start_quote_index = 0
        end_quote_index = None
        quote_length = None 
        end_index = None 
        tag_length = None
        index = 0 
        length = None 
        start_comment_index = 0
        end_comment_index = 0
        comment_length = None 

        # If you're not within a tag
        if self.previousBlockState() != States.TAG.value and self.previousBlockState() != States.QUOTE.value:
            # So we'll try to find the beginning of the next tag. 
            start_index = self.open_tag.indexIn(text)
        
        # Taking the state of the previous text block
        sub_previous_tag = self.previousBlockState()
        while start_index >= 0:
            # we are looking for an end tag
            end_index = self.close_tag.indexIn(text, start_index)

            # If the end tag is not found, then we'll set the block state. 
            if end_index == -1:
                self.setCurrentBlockState(States.TAG.value)
                tag_length = len(text) - start_index
            else:
                tag_length = end_index - start_index + self.close_tag.matchedLength()
            
            # Set the formatting for a tag
            if sub_previous_tag != States.TAG.value:
                # Since the beginning of the tag to the end, if the previous status is not equal Tag
                self.setFormat(start_index, 1, self.edge_tag_format)
                self.setFormat(start_index + 1, tag_length - 1, self.inside_tag_format)
            else:
                # If you're already inside the tag from the start block
                # and before the end tag. 
                self.setFormat(start_index, tag_length, self.inside_tag_format)
                sub_previous_tag = States.NONE.value 
            
            # Format the symbol of the end tag. 
            self.setFormat(end_index, 1, self.edge_tag_format)

            # QUOTES
            start_quote_index = 0
            # If you are not in quotation marks with the previous block
            if self.previousBlockState() != States.QUOTE.value:
                # So we'll try to find the beginning of the quotes
                start_quote_index = self.quotes.indexIn(text, start_index)

            # Highlight all quotes within the tag
            while start_quote_index >= 0 and ((start_quote_index < end_index) or (end_index == -1)):
                end_quote_index = self.quotes.indexIn(text, start_quote_index + 1)
                if end_quote_index == -1:
                    # If a closing quotation mark is found, set the state for the block quote. 
                    self.setCurrentBlockState(States.QUOTE.value)
                    quote_length = len(text) - start_quote_index
                else:
                    quote_length = end_quote_index - start_quote_index + self.quotes.matchedLength()
            
                if (end_index > end_quote_index) or end_index == -1:
                    self.setFormat(start_quote_index, quote_length, self.quotation_format)
                    start_quote_index = self.quotes.indexIn(text, start_quote_index + quote_length)
                
                else:
                    break 
            
            # Again, look for the beginning of the tag
            start_index = self.open_tag.indexIn(text, start_index + tag_length)

        # EDGES OF TAGS
        # Processing the color tags themselves, that is, highlight words div, p, strong etc. 
        for pattern, char_format in self.start_tag_rules:
            expression = QRegExp(pattern)
            index = expression.indexIn(text)
            while index >= 0:
                length = expression.matchedLength()
                self.setFormat(index + 1, length - 1, char_format)
                index = expression.indexIn(text, index + length)

        for pattern, char_format in self.end_tag_rules:
            expression = QRegExp(pattern)
            index = expression.indexIn(text)
            while index >= 0:
                length = expression.matchedLength()
                self.setFormat(index + 1, 1, self.edge_tag_format)
                self.setFormat(index + 2, length - 2, char_format)
                index = expression.indexIn(text, index + length)
        
        # COMMENT 
        start_comment_index = 0
        # If the tag is not a previous state commentary
        if self.previousBlockState() != States.COMMENT.value:
            # Then we'll try to find the beginning of a comment
            start_comment_index = self.comment_start_expression.indexIn(text)

        # If a comment is found
        while start_comment_index >= 0:
            # We are looking for the end of the comment. 
            end_comment_index = self.comment_end_expression.indexIn(text, start_comment_index)

            # If the end is not found 
            if end_comment_index == -1:
                # Then set the state comment
                # The principle is similar to that of conventional tags
                self.setCurrentBlockState(States.COMMENT.value)
                comment_length = len(text) - start_comment_index
            else:
                comment_length = end_comment_index - start_comment_index + self.comment_end_expression.matchedLength()
            
            self.setFormat(start_comment_index, comment_length, self.multi_line_comment_format)
            start_comment_index = self.comment_start_expression.indexIn(text, start_comment_index + comment_length)
Exemplo n.º 13
0
class HtmlHighlighter(QSyntaxHighlighter):
    def __init__(self, parent=None):
        super().__init__(parent)

        self.start_tag_rules = []
        self.end_tag_rules = []

        self.open_tag = QRegExp("<")
        self.close_tag = QRegExp(">")

        self.edge_tag_format = QTextCharFormat()
        self.edge_tag_format.setForeground(QBrush(QColor("#999999")))

        self.inside_tag_format = QTextCharFormat()
        self.inside_tag_format.setForeground(QBrush(QColor("#32A9DD"))) 

        self.comment_start_expression = QTextCharFormat() 
        self.commend_end_expression = QTextCharFormat() 
        self.multi_line_comment_format = QTextCharFormat() 

        self.quotes = QRegExp()
        self.quotation_format = QTextCharFormat()

        keywordFormat = QTextCharFormat()
        keywordFormat.setForeground(QColor("#2566ca"))

        keywordPatterns = ['<\\b!DOCTYPE\\b', '<\\ba\\b', '<\\babbr\\b', '<\\bacronym \\b', '<\\baddress\\b', 
        '<\\bapplet \\b', '<\\barea\\b', '<\\barticle\\b', '<\\baside\\b', '<\\baudio\\b', '<\\bb\\b', '<\\bbase\\b', '<\\bbasefont \\b', 
        '<\\bbdi\\b', '<\\bbdo\\b', '<\\bbig \\b', '<\\bblockquote\\b', '<\\bbody\\b', '<\\bbr\\b', '<\\bbutton\\b', '<\\bcanvas\\b', '<\\bcaption\\b', 
        '<\\bcenter \\b', '<\\bcite\\b', '<\\bcode\\b', '<\\bcol\\b', '<\\bcolgroup\\b', '<\\bcommand\\b', '<\\bdatalist\\b', '<\\bdd\\b', '<\\bdel\\b', 
        '<\\bdetails\\b', '<\\bdfn\\b', '<\\bdir\\b', '<\\bdiv\\b', '<\\bdl\\b', '<\\bdt\\b', '<\\bem\\b', '<\\bembed\\b', '<\\bfieldset\\b', '<\\bfigcaption\\b', 
        '<\\bfigure\\b', '<\\bfont\\b', '<\\bfooter\\b', '<\\bform\\b', '<\\bframe\\b', '<\\bframeset\\b', '<\\bh1\\b', '<\\bh2\\b', '<\\bh3\\b', '<\\bh4\\b', 
        '<\\bh5\\b', '<\\bh6\\b', '<\\bhead\\b', '<\\bheader\\b', '<\\bhgroup\\b', '<\\bhr\\b', '<\\bhtml\\b', '<\\bi\\b', '<\\biframe\\b', '<\\bimg\\b', 
        '<\\binput\\b', '<\\bins\\b', '<\\bkbd\\b', '<\\bkeygen\\b', '<\\blabel\\b', '<\\blegend\\b', '<\\bli\\b', '<\\blink\\b', '<\\bmap\\b', '<\\bmark\\b', 
        '<\\bmenu\\b', '<\\bmeta\\b', '<\\bmeter\\b', '<\\bnav\\b', '<\\bnoframes\\b', '<\\bnoscript\\b', '<\\bobject\\b', '<\\bol\\b', '<\\boptgroup\\b', 
        '<\\boption\\b', '<\\boutput\\b', '<\\bp\\b', '<\\bparam\\b', '<\\bpre\\b', '<\\bprogress\\b', '<\\bq\\b', '<\\brp\\b', '<\\brt\\b', '<\\bruby\\b', '<\\bs\\b', 
        '<\\bsamp\\b', '<\\bscript\\b', '<\\bsection\\b', '<\\bselect\\b', '<\\bsmall\\b', '<\\bsource\\b', '<\\bspan\\b', '<\\bstrike \\b', '<\\bstrong\\b', 
        '<\\bstyle\\b', '<\\bsub\\b', '<\\bsummary\\b', '<\\bsup\\b', '<\\btable\\b', '<\\btbody\\b', '<\\btd\\b', '<\\btextarea\\b', '<\\btfoot\\b', '<\\bth\\b', 
        '<\\bthead\\b', '<\\btime\\b', '<\\btitle\\b', '<\\btr\\b', '<\\btrack\\b', '<\\btt\\b', '<\\bu\\b', '<\\bul\\b', '<\\bvar\\b', '<\\bvideo\\b', '<\\bwbr\\b', 
        ]
        self.start_tag_rules = [(QRegExp(pattern), keywordFormat) for pattern in keywordPatterns]

        keywordPatterns_end = ['</\\ba\\b', '</\\babbr\\b', '</\\bacronym \\b', '</\\baddress\\b', '</\\bapplet \\b', '</\\barea\\b', '</\\barticle\\b', '</\\baside\\b', 
        '</\\baudio\\b', '</\\bb\\b', '</\\bbase\\b', '</\\bbasefont \\b', '</\\bbdi\\b', '</\\bbdo\\b', '</\\bbig \\b', '</\\bblockquote\\b', '</\\bbody\\b', 
        '</\\bbr\\b', '</\\bbutton\\b', '</\\bcanvas\\b', '</\\bcaption\\b', '</\\bcenter \\b', '</\\bcite\\b', '</\\bcode\\b', '</\\bcol\\b', '</\\bcolgroup\\b', 
        '</\\bcommand\\b', '</\\bdatalist\\b', '</\\bdd\\b', '</\\bdel\\b', '</\\bdetails\\b', '</\\bdfn\\b', '</\\bdir\\b', '</\\bdiv\\b', '</\\bdl\\b', '</\\bdt\\b', 
        '</\\bem\\b', '</\\bembed\\b', '</\\bfieldset\\b', '</\\bfigcaption\\b', '</\\bfigure\\b', '</\\bfont\\b', '</\\bfooter\\b', '</\\bform\\b', '</\\bframe\\b', 
        '</\\bframeset\\b', '</\\bh1\\b', '</\\bh2\\b', '</\\bh3\\b', '</\\bh4\\b', '</\\bh5\\b', '</\\bh6\\b', '</\\bhead\\b', '</\\bheader\\b', '</\\bhgroup\\b', 
        '</\\bhr\\b', '</\\bhtml\\b', '</\\bi\\b', '</\\biframe\\b', '</\\bimg\\b', '</\\binput\\b', '</\\bins\\b', '</\\bkbd\\b', '</\\bkeygen\\b', '</\\blabel\\b', 
        '</\\blegend\\b', '</\\bli\\b', '</\\blink\\b', '</\\bmap\\b', '</\\bmark\\b', '</\\bmenu\\b', '</\\bmeta\\b', '</\\bmeter\\b', '</\\bnav\\b', 
        '</\\bnoframes\\b', '</\\bnoscript\\b', '</\\bobject\\b', '</\\bol\\b', '</\\boptgroup\\b', '</\\boption\\b', '</\\boutput\\b', '</\\bp\\b', '</\\bparam\\b', 
        '</\\bpre\\b', '</\\bprogress\\b', '</\\bq\\b', '</\\brp\\b', '</\\brt\\b', '</\\bruby\\b', '</\\bs\\b', '</\\bsamp\\b', '</\\bscript\\b', '</\\bsection\\b', 
        '</\\bselect\\b', '</\\bsmall\\b', '</\\bsource\\b', '</\\bspan\\b', '</\\bstrike \\b', '</\\bstrong\\b', '</\\bstyle\\b', '</\\bsub\\b', '</\\bsummary\\b', 
        '</\\bsup\\b', '</\\btable\\b', '</\\btbody\\b', '</\\btd\\b', '</\\btextarea\\b', '</\\btfoot\\b', '</\\bth\\b', '</\\bthead\\b', '</\\btime\\b', 
        '</\\btitle\\b', '</\\btr\\b', '</\\btrack\\b', '</\\btt\\b', '</\\bu\\b', '</\\bul\\b', '</\\bvar\\b', '</\\bvideo\\b', '</\\bwbr\\b'
        ]
        self.end_tag_rules = [(QRegExp(pattern), keywordFormat) for pattern in keywordPatterns_end]
     
        self.multi_line_comment_format.setForeground(Qt.darkGray)
        self.comment_start_expression = QRegExp("<!--")
        self.comment_end_expression = QRegExp("-->")

        self.quotation_format.setForeground(QBrush(QColor("#FDA172")))
        self.quotes = QRegExp("\"")

    def highlightBlock(self, text):
        self.setCurrentBlockState(States.NONE.value)

        # TAG
        start_index = 0
        start_quote_index = 0
        end_quote_index = None
        quote_length = None 
        end_index = None 
        tag_length = None
        index = 0 
        length = None 
        start_comment_index = 0
        end_comment_index = 0
        comment_length = None 

        # If you're not within a tag
        if self.previousBlockState() != States.TAG.value and self.previousBlockState() != States.QUOTE.value:
            # So we'll try to find the beginning of the next tag. 
            start_index = self.open_tag.indexIn(text)
        
        # Taking the state of the previous text block
        sub_previous_tag = self.previousBlockState()
        while start_index >= 0:
            # we are looking for an end tag
            end_index = self.close_tag.indexIn(text, start_index)

            # If the end tag is not found, then we'll set the block state. 
            if end_index == -1:
                self.setCurrentBlockState(States.TAG.value)
                tag_length = len(text) - start_index
            else:
                tag_length = end_index - start_index + self.close_tag.matchedLength()
            
            # Set the formatting for a tag
            if sub_previous_tag != States.TAG.value:
                # Since the beginning of the tag to the end, if the previous status is not equal Tag
                self.setFormat(start_index, 1, self.edge_tag_format)
                self.setFormat(start_index + 1, tag_length - 1, self.inside_tag_format)
            else:
                # If you're already inside the tag from the start block
                # and before the end tag. 
                self.setFormat(start_index, tag_length, self.inside_tag_format)
                sub_previous_tag = States.NONE.value 
            
            # Format the symbol of the end tag. 
            self.setFormat(end_index, 1, self.edge_tag_format)

            # QUOTES
            start_quote_index = 0
            # If you are not in quotation marks with the previous block
            if self.previousBlockState() != States.QUOTE.value:
                # So we'll try to find the beginning of the quotes
                start_quote_index = self.quotes.indexIn(text, start_index)

            # Highlight all quotes within the tag
            while start_quote_index >= 0 and ((start_quote_index < end_index) or (end_index == -1)):
                end_quote_index = self.quotes.indexIn(text, start_quote_index + 1)
                if end_quote_index == -1:
                    # If a closing quotation mark is found, set the state for the block quote. 
                    self.setCurrentBlockState(States.QUOTE.value)
                    quote_length = len(text) - start_quote_index
                else:
                    quote_length = end_quote_index - start_quote_index + self.quotes.matchedLength()
            
                if (end_index > end_quote_index) or end_index == -1:
                    self.setFormat(start_quote_index, quote_length, self.quotation_format)
                    start_quote_index = self.quotes.indexIn(text, start_quote_index + quote_length)
                
                else:
                    break 
            
            # Again, look for the beginning of the tag
            start_index = self.open_tag.indexIn(text, start_index + tag_length)

        # EDGES OF TAGS
        # Processing the color tags themselves, that is, highlight words div, p, strong etc. 
        for pattern, char_format in self.start_tag_rules:
            expression = QRegExp(pattern)
            index = expression.indexIn(text)
            while index >= 0:
                length = expression.matchedLength()
                self.setFormat(index + 1, length - 1, char_format)
                index = expression.indexIn(text, index + length)

        for pattern, char_format in self.end_tag_rules:
            expression = QRegExp(pattern)
            index = expression.indexIn(text)
            while index >= 0:
                length = expression.matchedLength()
                self.setFormat(index + 1, 1, self.edge_tag_format)
                self.setFormat(index + 2, length - 2, char_format)
                index = expression.indexIn(text, index + length)
        
        # COMMENT 
        start_comment_index = 0
        # If the tag is not a previous state commentary
        if self.previousBlockState() != States.COMMENT.value:
            # Then we'll try to find the beginning of a comment
            start_comment_index = self.comment_start_expression.indexIn(text)

        # If a comment is found
        while start_comment_index >= 0:
            # We are looking for the end of the comment. 
            end_comment_index = self.comment_end_expression.indexIn(text, start_comment_index)

            # If the end is not found 
            if end_comment_index == -1:
                # Then set the state comment
                # The principle is similar to that of conventional tags
                self.setCurrentBlockState(States.COMMENT.value)
                comment_length = len(text) - start_comment_index
            else:
                comment_length = end_comment_index - start_comment_index + self.comment_end_expression.matchedLength()
            
            self.setFormat(start_comment_index, comment_length, self.multi_line_comment_format)
            start_comment_index = self.comment_start_expression.indexIn(text, start_comment_index + comment_length)