20 lines
558 B
Python
20 lines
558 B
Python
#!/usr/bin/python3
|
|
|
|
import re
|
|
from PyQt6.QtGui import QSyntaxHighlighter
|
|
|
|
|
|
class Higlighter(QSyntaxHighlighter):
|
|
def __init__(self, parent=None):
|
|
QSyntaxHighlighter.__init__(self, parent)
|
|
|
|
self.mappings = {}
|
|
|
|
def add_mapping(self, pattern, format):
|
|
self.mappings[pattern] = format
|
|
|
|
def highlightBlock(self, text):
|
|
for pattern, format in self.mappings.items():
|
|
for match in re.finditer(pattern, text):
|
|
start, end = match.span()
|
|
self.setFormat(start, end - start, format)
|