Skip to content

BaseRuleSyntaxHighlighter

Qt Base Class: QSyntaxHighlighter

Signature: QSyntaxHighlighter(self, parent: PySide6.QtCore.QObject) -> None QSyntaxHighlighter(self, parent: PySide6.QtGui.QTextDocument) -> None

Base classes

Name Children Inherits
SyntaxHighlighter
prettyqt.gui.syntaxhighlighter

Subclasses

Class Module Description
MarkdownHighlighter prettyqt.syntaxhighlighters.markdownhighlighter
PythonHighlighter prettyqt.syntaxhighlighters.pythonhighlighter
YamlHighlighter prettyqt.syntaxhighlighters.yamlhighlighter

⋔ Inheritance diagram

graph TD
  1473296248080["syntaxhighlighters.BaseRuleSyntaxHighlighter"]
  1473245668528["gui.SyntaxHighlighter"]
  1473245664624["gui.SyntaxHighlighterMixin"]
  1473299815024["core.ObjectMixin"]
  140713234304496["builtins.object"]
  1473289231040["QtGui.QSyntaxHighlighter"]
  1473288842240["QtCore.QObject"]
  1473291690208["Shiboken.Object"]
  1473245668528 --> 1473296248080
  1473245664624 --> 1473245668528
  1473299815024 --> 1473245664624
  140713234304496 --> 1473299815024
  1473289231040 --> 1473245668528
  1473288842240 --> 1473289231040
  1473291690208 --> 1473288842240
  140713234304496 --> 1473291690208

🛈 DocStrings

Bases: SyntaxHighlighter

Source code in prettyqt\syntaxhighlighters\baserulesyntaxhighlighter.py
class BaseRuleSyntaxHighlighter(gui.SyntaxHighlighter):
    RULES: list = []

    @classmethod
    def iter_rules(cls) -> Iterator[tuple[Pattern, int, gui.TextCharFormat]]:
        for rule in cls.RULES:
            if isinstance(rule.compiled, list):
                for i in rule.compiled:
                    yield (i, rule.nth, rule.fmt)
            else:
                yield (rule.compiled, rule.nth, rule.fmt)

    def highlightBlock(self, text: str):
        """Apply syntax highlighting to the given block of text."""
        # Do other syntax formatting
        for expression, nth, fmt in self.iter_rules():
            for match in expression.finditer(text):
                span = match.span(nth)
                self.setFormat(span[0], span[1] - span[0], fmt)

highlightBlock(text: str)

Apply syntax highlighting to the given block of text.

Source code in prettyqt\syntaxhighlighters\baserulesyntaxhighlighter.py
def highlightBlock(self, text: str):
    """Apply syntax highlighting to the given block of text."""
    # Do other syntax formatting
    for expression, nth, fmt in self.iter_rules():
        for match in expression.finditer(text):
            span = match.span(nth)
            self.setFormat(span[0], span[1] - span[0], fmt)

⌗ Property table

Qt Property Type Doc
objectName QString