The highlighter module#
This module provides a SyntaxHighlighter.
- class SyntaxHighlighter(worker)[source]#
Bases:
SingleInstanceProvides syntax highlighting using parce parsers.
Instantiate with:
SyntaxHighlighter.instance(worker)
You need to set a
Formatterwhich supplies the highlighting text formats.By default, no formatter is set; use
set_formatter()to set a Formatter, which is needed to enable highlighting.- set_formatter(formatter)[source]#
Set the Formatter to use, or None for no formatter.
The Formatter provides the text formats to highlight. If you set the Formatter to None, highlighting is effectively disabled, although the TreeBuilder still does the tokenizing.
- clear()[source]#
Clear the highlighting.
This method is called when the formatter is set to None, and when SyntaxHighlighter is explicitedly
delete()-d.
- rehighlight()[source]#
Draw or clear the highlighting, depending on the Formatter.
This method is automatically called when the Formatter is changed. Clears the highlighting if the current formatter is None.
- draw_highlighting(root, start, end, interruptible=False)[source]#
Draw the highlighting using tree
rootfromstarttoend.If
interruptibleis True,QApplication::process_events()is called every 1000 lines, to enable the user typing in the document, which also causes the highlighting to quit and resume later.
- split_formats(block, position)[source]#
Return two lists of FormatRange instances from the block’s layout.
The first are the formats from the start of the block until position (which must be inside the block). The second are the formats from the position to the end of the block, shifted as if the block started at position.
A format range is neatly cut in two when position lies in the middle of a range.