Syntax highlighting in own component

Andy borucki.andrzej at gmail.com
Sun Aug 6 09:35:06 BST 2023


Context is private.
If I wanna alone analyse strings for highlighting, I need xml files.
Here is well explained:
https://docs.kde.org/stable5/en/kate/katepart/highlight.html
To better understand dynamic rules I need examples:
Let analyse line (with definition in xml.xml from
https://kate-editor.org/syntax/data/syntax/)

QString text = R"(   <namespace key="-1" case="first-letter">Specjalna
& &t</namespace>)";

Three spaces at begin and "<" char followed by identifier.
context "FindXML"
is rule "Element Symbols" with String="<(?=(&name;))" where
<!ENTITY name    "(?![0-9])[\w_:][\w.:_-]*">
thus rule is "<(?=((?![0-9])[\\w_:][\\w.:_-]*))"
this match "<" because after is "<" is identifier
Then go to context "ElementTagName"

<context name="ElementTagName" attribute="Other Text"
lineEndContext="#pop!Element">
  <StringDetect attribute="Element" context="#pop!Element" String="%1"
dynamic="true" />
</context>

I can't understand this: detect string after "<"? how to get string "namespace"
I use code
QRegularExpression regex("<(?=((?![0-9])[\\w_:][\\w.:_-]*))");
QRegularExpressionMatch match = regex.match(text);

match.captured() is "<'
but can I get "namespace" from match?
Here is %1 but can be %2 or %3 - how to use it?


More information about the kde-devel mailing list