def highlightBlock(self, text):
        # highlight patterns
        for i in range(0, len(self.patterns)):
            p = self.patterns[i]
            for match in p[0].finditer(text):
                self.setFormat(
                    match.start(), match.end() - match.start(), p[1])

        if text == '' and self.currentBlock().next().text() != '':
            self.setCurrentBlockState(self.previousBlockState()) 
            #this is turned highlighting back on accidentally, by setting it to 5
        elif self.previousBlockState() == 3:
            self.setFormat(0, len(text), self.patterns[1][1])
            self.setCurrentBlockState(0)
        elif self.previousBlockState() == 4:
            self.setFormat(0, len(text), self.patterns[2][1])
            self.setCurrentBlockState(0)
        else:
            # escape highlights in fenced_block
            m = self.fenced_block.match(text)
            m2 = self.math_block.match(text)
            #print(m, m2)
            self.setCurrentBlockState(0)

            if self.previousBlockState() not in (1,2):
                if m:
                    self.setCurrentBlockState(1)
                #checking if an asciimathml block needs to be continued is a lot simpler
                elif m2 and not (text[m2.start():m2.end()].endswith("$$") and not text == "$$"):
                    self.setCurrentBlockState(2)
                else:
                    if self.settext_h1.match(self.currentBlock().next().text()) and text != '':
                        self.setFormat(0, len(text), self.patterns[1][1])
                        self.setCurrentBlockState(3)
                    elif self.settext_h2.match(self.currentBlock().next().text()) and text != '':
                        self.setFormat(0, len(text), self.patterns[2][1])
                        self.setCurrentBlockState(4)

            elif self.previousBlockState() == 1:
                if m:
                    self.setCurrentBlockState(0)
                else:
                    self.setCurrentBlockState(1)
                    self.setFormat(0, len(text), self.fenced_format)
            elif self.previousBlockState() == 2:
                if m2:
                    self.setCurrentBlockState(0)
                else:
                    self.setCurrentBlockState(2)
                    self.setFormat(0, len(text), self.math_format)
        #print(self.currentBlockState(), text)

        self.highlightSpellcheck(text)
dataset/ETHPy150Open ShadowKyogre/mikidown/mikidown/highlighter.py/MikiHighlighter.highlightBlock/original