Open AlexCzar opened 4 years ago
This is actually pretty complicated, since Qt by itself doesn't support this. We would need to write our own custom renderer for text elements or wait for Qt to add a more extensible API like https://bugreports.qt.io/browse/QTBUG-85651. I doubt we'll see something like this soon, the closest thing we could probably get in the near future would be a background color. Alternatively we could split the rendering into multiple text elements, but that would complicate our logic a lot too.
Found this:
Accepted answer: Qt Quick's TextEdit item exposes a textDocument property, of type QQuickTextDocument. This is explicitly exposed so you can use QSyntaxHighlighter directly with the document.
at https://stackoverflow.com/questions/14791360/qt5-syntax-highlighting-in-qml
other answers are interesting as well.
I don't think it is that simple, since we don't want to syntax highlight the full TextEdit, but only the <pre>
tags within it. We also need to guess the programming language, etc.
The language is sent as meta datum, Nheko at least sends <code class="language-shell">
if you type “``` shell”.
Could this be done using treesitter? https://tree-sitter.github.io/tree-sitter/syntax-highlighting
Describe the solution you'd like I'd like multi-line code blocks to be syntax highlighted, it would be nice (but not absolutely necessary) if highlighting theme could be chosen in settings.
Describe alternatives you've considered The only alternative solution for now is to use Riot web client.