Implement highlight specific for CSS and HTML.

def highlight_block(self, text):
        """Implement highlight specific for CSS and HTML."""
        text = to_text_string(text)
        previous_state = tbh.get_state(self.currentBlock().previous())
        
        if previous_state == self.COMMENT:
            self.setFormat(0, len(text), self.formats["comment"])
        else:
            previous_state = self.NORMAL
            self.setFormat(0, len(text), self.formats["normal"])
        
        tbh.set_state(self.currentBlock(), previous_state)
        match = self.PROG.search(text)        

        match_count = 0
        n_characters = len(text)
        # There should never be more matches than characters in the text.
        while match and match_count < n_characters:
            match_dict = match.groupdict()
            for key, value in list(match_dict.items()):
                if value:
                    start, end = match.span(key)
                    if previous_state == self.COMMENT:
                        if key == "multiline_comment_end":
                            tbh.set_state(self.currentBlock(), self.NORMAL)
                            self.setFormat(end, len(text),
                                           self.formats["normal"])
                        else:
                            tbh.set_state(self.currentBlock(), self.COMMENT)
                            self.setFormat(0, len(text),
                                           self.formats["comment"])
                    else:
                        if key == "multiline_comment_start":
                            tbh.set_state(self.currentBlock(), self.COMMENT)
                            self.setFormat(start, len(text),
                                           self.formats["comment"])
                        else:
                            tbh.set_state(self.currentBlock(), self.NORMAL)
                            try:
                                self.setFormat(start, end-start,
                                               self.formats[key])
                            except KeyError:
                                # happens with unmatched end-of-comment;
                                # see issue 1462
                                pass
            
            match = self.PROG.search(text, match.end())
            match_count += 1
        
        self.highlight_spaces(text)