SUMMARY javascript-react.xml contains: <DetectChar attribute="Normal Text" context="NoRegExp##JavaScript" char="]" endRegion="List" /> My reading of https://docs.kde.org/stable5/en/applications/katepart/highlight.html only says that a Rule's context can contain references like: "The context can be identified by: 1. An identifier, which is the name of the other context. 2. An order telling the engine to stay in the current context (#stay), or to pop back to a previous context used in the string (#pop). 3. To go back more steps, the #pop keyword can be repeated: #pop#pop#pop 4. An order followed by an exclamation mark (!) and an identifier, which will make the engine first follow the order and then switch to the other context, e.g. #pop#pop!OtherContext. " Only <IncludeRules> or <list><include> can contain name##file refs. STEPS TO REPRODUCE 1. Load a .html file into a syntax highlighting engine. This includes javascript-react.xml OBSERVED RESULT A complaint about the NoRegExp##JavaScript not being local EXPECTED RESULT There should not be file ref like NoRegExp##JavaScript in a Rule's context SOFTWARE/OS VERSIONS Windows: macOS: Linux/KDE Plasma: (available in About System) KDE Plasma Version: KDE Frameworks Version: Qt Version: head of https://github.com/KDE/syntax-highlighting ADDITIONAL INFORMATION
Of the 28,000 rule lines in the syntax directory, only 10 use extern file ref context attributes. These are a mistake are they not? coffee.xml:270: <Detect2Chars attribute="JavaScript Template" context="RegExpAfterString##JavaScript" char="\" char1="`" endRegion="Template"/> <!-- End template. --> coffee.xml:292: <Detect2Chars attribute="JavaScript Template" context="RegExpAfterString##JavaScript" char="\" char1="`" endRegion="Template"/> <!-- End template. --> javascript-react.xml:81: <DetectChar attribute="Normal Text" context="NoRegExp##JavaScript" char="]" endRegion="List" /> javascript-react.xml:96: <DetectChar context="RegExpAfterString##JavaScript" attribute="Template" char="`" endRegion="Template" /> qml.xml:121: <RegExpr attribute="Objects" context="FindMemberObjectMath##JavaScript" String="\bMath(?=\s*\.)" /> qml.xml:148: <DetectChar attribute="String" context="RegExpAfterString##JavaScript" char=""" /> selinux-fc.xml:90: <IncludeRules context="_m4_builtin_keywords##SELinux Policy"/> typescript.xml:406: <DetectChar context="RegExpAfterString##JavaScript" attribute="Template" char="`" endRegion="Template" /> typescript-react.xml:103: <DetectChar context="RegExpAfterString##JavaScript" attribute="Template" char="`" endRegion="Template" /> yara.xml:66: <RegExpr attribute="Start Regular Expression" context="(regex caret first check)##JavaScript" String="/(?=(?:[^/\\\[]|\\.|\[(?:[^\]\\]|\\.)+\])+/(?:[gimsuy]+(?!\s*[\w$])|(?![/\*])|(?=/\*)))" />
This is valid and it works! Using "NoRegExp##JavaScript" switches to the "NoRegExp" context of the "JavaScript" definition. Apparently this type of context switch isn't in the documentation, I will have to add it.
I added this context switch to the documentation: """ An identifier, which is a context name, followed by two hashes (##) and another identifier, which is the name of a language definition. This naming is similar to that used in IncludeRules rules and allows you to switch to a context belonging to another syntax highlighting definition, e.g. "SomeContext##JavaScript". Note that it is not possible to use this context switch in combination with #pop, for example, "#pop!SomeContext##JavaScript" is not valid. """ See the commit here: https://invent.kde.org/utilities/kate/-/commit/858b18d7a8d49348e4d4e24531f36e4f93cc6834 The documentation is not updated automatically, so we will have to wait. In case you still have doubts, you can check the KSyntaxHighlighting source code: https://invent.kde.org/frameworks/syntax-highlighting/-/blob/master/src/lib/contextswitch.cpp#L47