Syntax highlighting in own component

Andy borucki.andrzej at gmail.com
Sat Aug 5 13:29:29 BST 2023


I am writing component for viewing huge files > 4 GiB, which are not
loaded to memory. (https://github.com/siplasplas/qt-textviewer)

I want add syntax highlighting (and maybe folding), but I can’t use
QTextDocument because my fro ground widget not keep whole text in
memory and number lines is unknown. Also I can’t probably use
KsyntaxHighlighting::SyntaxHighlighter because it requires
QtextDocument

I wanna use KsyntaxHighlighting::Repository,
KsyntaxHighlighting::Definition and KSyntaxHighlighting::Format.
Definition has methods/fields such as foldingEnabled or
multiLineCommentMarker. Format has method returning at once text
styles for thema, and I can’t find methods for rules, for example rule
to detect int decimal or octal or string.
I have cloned https://invent.kde.org/frameworks/syntax-highlighting,but
I can’t find there code to explain me. For example,

in SyntaxHighlighter::highlightBlock is

```
const auto nextBlock = currentBlock().next();
    if (nextBlock.isValid()) {
        QMetaObject::invokeMethod(this, "rehighlightBlock",
Qt::QueuedConnection, Q_ARG(QTextBlock, nextBlock));
    }
```
but I don't find "rehighlightBlock" in any other place in whole repository.


More information about the kde-devel mailing list