"""Simple JSON/general syntax highlighter for QTextEdit.""" import re from PyQt6.QtGui import QSyntaxHighlighter, QTextCharFormat, QColor, QFont class JsonHighlighter(QSyntaxHighlighter): def __init__(self, parent=None): super().__init__(parent) self._rules = [] def fmt(color, bold=False): f = QTextCharFormat() f.setForeground(QColor(color)) if bold: f.setFontWeight(QFont.Weight.Bold) return f # Keys self._rules.append((re.compile(r'"([^"\\]|\\.)*"\s*(?=:)'), fmt("#9CDCFE"))) # String values self._rules.append((re.compile(r'(?