<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE language[ <!ENTITY simpleName "(?:[a-z][a-z\d]*:)?[a-z][a-z\d]*"> <!ENTITY baseName "[a-zA-Z_\$[:^ascii:]](?:[\w\$\-\.[:^ascii:]]*[\w\$[:^ascii:]])?"> <!ENTITY name "(?:&baseName;:)?&baseName;"> <!ENTITY baseNameWithBound "(?:\b[a-zA-Z_\$]|[^[:ascii:]])(?:[\w\$\-\.[:^ascii:]]*[\w\$[:^ascii:]])?"> <!ENTITY nameWithBound "(?:&baseNameWithBound;:)?&baseNameWithBound;"> <!-- Use this instead of "\b&name;" --> <!ENTITY simpleTag "<\s*&simpleName;"> <!-- Element tag --> <!ENTITY tag "<\s*(?:&name;|>)"> <!ENTITY entref "&(?:[a-zA-Z\d]+|#\d+|#x[a-fA-F\d]+);"> <!ENTITY mlComment "/\*(?:[^\*]|\*+[^/\*])*\*+/"> <!ENTITY endTagName "[\s<>]|/[>/\*]|$"> <!-- Delimiter of end of Tag name --> <!ENTITY identifier "[a-zA-Z_$[:^ascii:]][\w$[:^ascii:]]*">]><!-- ==================================================================== This file is part of the KDE's KSyntaxHighlighting framework. Copyright 2018-2020 Nibaldo González S. (nibgonz@gmail.com) This Source Code Form is subject to the terms of the MIT License. If a copy of the license was not distributed with this file, You can obtain one at: https://opensource.org/licenses/MIT ==================================================================== This file is an extension of the JavaScript highlighter (javascript.xml, Version 14 and higher). IMPORTANT: Keep sync with "typescript-react.xml". Based on the XML syntax highlighting (v7), by Wilbert Berendsen (wilbert@kde.nl), and the TypeScript React grammar files, available at: https://github.com/Microsoft/TypeScript-TmLanguage Change log: * v9 [2020-06-03]: Add folding in templates. * v8 [2019-11-21]: Tag detection is more stricter. * v7 [2019-11-19]: Rename definition "JavaScript React" to "JavaScript React (JSX)". * v5 [2019-02-20]: Don't highlight tags within declarations of types, variables, classes and interfaces. Fixes tags after substitutions in templates. Reorder part of the code. * v4 [2018-12-30]: Allow type assertion in the tag name. Allow tags after the keywords "await" & "yield". Allow empty tags and non-ASCII tag name & attributes. * v3 [2018-11-18]: Fix Doxygen comments & shebang. Remove TSX extension. * v2 [2018-08-18]: Remove "Conditional Expression" context. * v1 [2018-06-20]: Initial version--><language name="JavaScript React (JSX)" alternativeNames="JSX" version="11" kateversion="5.53" section="Scripts" indenter="cstyle" priority="9" extensions="*.jsx" mimetype="text/jsx;text/x-jsx;application/jsx;application/x-jsx;" author="Nibaldo González (nibgonz@gmail.com)" license="MIT"><highlighting> <contexts> <context name="Shebang" attribute="Normal Text" lineEndContext="#pop!Normal" lineEmptyContext="#pop!Normal" fallthrough="true" fallthroughContext="#pop!Normal"> <Detect2Chars context="ShebangLine" attribute="Comment" char="#" char1="!" column="0" /> </context> <context name="ShebangLine" attribute="Comment" lineEndContext="#pop#pop!Normal" /> <context name="Normal" attribute="Normal Text" lineEndContext="#stay"> <IncludeRules context="React" /> <IncludeRules context="Normal##JavaScript" /> </context> <!-- JavaScript --> <!-- Overwrite rules of 'javascript.xml'. These rules send to contexts that contain: <IncludeRules context="Normal"/> in the JavaScript XML file. --> <context name="OverwriteJavaScript" attribute="Normal Text" lineEndContext="#stay"> <DetectChar context="Template" attribute="Template" char="`" beginRegion="Template" /> <DetectChar attribute="Normal Text" context="#stay" char="[" beginRegion="List" /> <DetectChar attribute="Normal Text" context="NoRegExp##JavaScript" char="]" endRegion="List" /> <!-- NOTE: The "{" character sends to the "Object" context (see the "React" context) --> </context> <context name="Object" attribute="Normal Text" lineEndContext="#stay"> <DetectChar context="#pop" attribute="Normal Text" char="}" endRegion="Brace" /> <IncludeRules context="React" /> <RegExpr context="ConditionalExpression" attribute="Symbol" String="\?(?=[^\{\}]*&identifier;\s*\:)" /> <IncludeRules context="Object##JavaScript" /> </context> <context name="ConditionalExpression" attribute="Normal Text" lineEndContext="#pop"> <DetectChar context="#pop" attribute="Symbol" char=":" /> <IncludeRules context="React" /> <IncludeRules context="ConditionalExpression##JavaScript" /> </context> <context name="Template" attribute="Template" lineEndContext="#stay"> <DetectChar context="RegExpAfterString##JavaScript" attribute="Template" char="`" endRegion="Template" /> <!-- Find tags and send to the "Substitution" context --> <Detect2Chars context="Substitution-BeforeTag" attribute="Substitution" char="$" char1="{" /> <IncludeRules context="Template##JavaScript" /> </context> <context name="Substitution" attribute="Normal Text" lineEndContext="#stay"> <DetectChar context="#pop" attribute="Substitution" char="}" /> <IncludeRules context="React" /> <IncludeRules context="Substitution##JavaScript" /> </context> <!-- Do not highlight tags in some special contexts --> <context name="FindDeclarationsWithNoTags" attribute="Normal Text" lineEndContext="#stay"> <WordDetect context="InterfaceDeclaration" attribute="Reserved" String="interface" /> <WordDetect context="ClassDeclaration" attribute="Reserved" String="class" /> <WordDetect context="VarDeclaration" attribute="Reserved" String="let" /> <WordDetect context="VarDeclaration" attribute="Keyword" String="var" /> <WordDetect context="VarDeclaration" attribute="Keyword" String="const" /> </context> <!-- Do not highlight tags after ":" in variable declarations --> <context name="VarDeclaration" attribute="Normal Text" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop"> <DetectSpaces /> <DetectChar context="#pop!NoTag" attribute="Symbol" char=":" /> <RegExpr context="#stay" attribute="Normal Text" String="&identifier;(?=\s*(?:[\?!]\s*)?:)" /> <AnyChar context="#stay" attribute="Symbol" String="?!" /> <IncludeRules context="AllComments" /> </context> <context name="NoTag" attribute="Normal Text" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop"> <DetectSpaces /> <IncludeRules context="AllComments" /> <DetectChar context="#pop" attribute="Symbol" char="<" /> <RegExpr context="#stay" attribute="Normal Text" String="\(\s*(?=<)" /> <RegExpr context="#stay" attribute="Normal Text" String="\[\s*(?=<)" beginRegion="List" /> <RegExpr context="#pop!Object" attribute="Normal Text" String="\{\s*<(\s*/(?![\*/]))?" beginRegion="Brace" /> </context> <!-- Do not highlight tags in interface declarations --> <context name="InterfaceDeclaration" attribute="Normal Text" lineEndContext="#stay"> <DetectChar context="#pop!InterfaceContentDeclaration" attribute="Normal Text" char="{" beginRegion="Brace" /> <DetectChar context="#pop" char="}" lookAhead="true" /> <IncludeRules context="Normal##JavaScript" /> </context> <context name="InterfaceContentDeclaration" attribute="Normal Text" lineEndContext="#stay"> <DetectChar context="#pop" attribute="Normal Text" char="}" endRegion="Brace" /> <IncludeRules context="Object##JavaScript" /> </context> <!-- Do not highlight tags in class declarations --> <context name="ClassDeclaration" attribute="Normal Text" lineEndContext="#stay"> <DetectChar context="#pop!ClassDeclarationContent" attribute="Normal Text" char="{" beginRegion="Brace" /> <DetectChar context="#pop" char="}" lookAhead="true" /> <IncludeRules context="Normal##JavaScript" /> </context> <context name="ClassDeclarationContent" attribute="Normal Text" lineEndContext="#stay"> <DetectChar context="#pop" attribute="Normal Text" char="}" endRegion="Brace" /> <DetectChar context="NoTag" attribute="Symbol" char=":" /> <IncludeRules context="Object" /> </context> <!-- ReactJS --> <!-- Tags highlighting --> <context name="React" attribute="Normal Text" lineEndContext="#stay"> <!-- Tag in new line --> <RegExpr context="ValidTag" attribute="Normal Text" String="&tag;" firstNonSpace="true" lookAhead="true" /> <!-- Highlight tags only after some keywords --> <RegExpr context="ValidTag" attribute="ControlFlow" String="\b(?:return|await)\s*(?=&tag;|/\*)" /> <RegExpr context="ValidTag" attribute="Module" String="\b(?:default)\s*(?=&tag;|/\*)" /> <RegExpr context="ValidTag" attribute="Reserved" String="\b(?:yield)\s*(?=&tag;|/\*)" /> <!-- Characters before a valid tag --> <RegExpr context="ValidTag" attribute="Special Operators" String="\=>\s*(?=&tag;|/\*)" /> <RegExpr context="ValidTag" attribute="Symbol" String="(?:[,\=>:\*\?]|&&|\|\|)\s*(?=&tag;|/\*)" /> <RegExpr context="ValidTag" attribute="Normal Text" String="\[\s*(?=&tag;|/\*)" beginRegion="List" /> <RegExpr context="ValidTag" attribute="Normal Text" String="\(\s*(?=&tag;|/\*)" /> <!-- The "Object-BeforeTag" context looks for a valid Tag and then sends the "Object" context --> <DetectChar context="Object-BeforeTag" attribute="Normal Text" char="{" beginRegion="Brace" /> <RegExpr context="ValidTag" attribute="Symbol" String="<\s*>\s*(?=&tag;|/\*)" /> <!-- Tag after a comment on a new line --> <Detect2Chars context="ValidTag" attribute="Comment" char="/" char1="*" firstNonSpace="true" lookAhead="true" /> <!-- Overwrite JavaScript rules to highlight tags within some contexts --> <IncludeRules context="FindDeclarationsWithNoTags" /> <IncludeRules context="OverwriteJavaScript" /> </context> <!-- Detect tags before starting a context --> <context name="Object-BeforeTag" attribute="Normal Text" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop!Object"> <IncludeRules context="ValidTag" /> </context> <context name="Substitution-BeforeTag" attribute="Normal Text" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop!Substitution"> <IncludeRules context="ValidTag" /> </context> <context name="EvaluatedCode-BeforeTag" attribute="Normal Text" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop!EvaluatedCode"> <IncludeRules context="ValidTag" /> </context> <!-- TAGS: NOTE & TODO: The following code is common for 'javascript-react.xml' and 'typescript-react.xml' and is replicated in both files. Look for some way to avoid having repeated code, for example, with a common XML file or with a generator script. The only drawback is that the "EvaluatedCode" context includes "Normal". --> <!-- Highlight nested tags with comments in between. NOTE: The highlighting of Tags after a multiline comment does not work with: lineEndContext="#pop" --> <context name="ValidTag" attribute="Normal Text" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop"> <RegExpr context="#stay" attribute="Normal Text" String="\s+(?=<|/\*)" /> <IncludeRules context="FindTags" /> <IncludeRules context="AllComments" /> </context> <!-- Start tag. There are two contexts to find Tags: * FindTags: For Tags within TypeScript code; invalid name tags aren't highlighted. * FindTagsInTagContent: For Tag within another tag; highlight any Tag. Tags with invalid names are highlighted as "Error". --> <context name="FindTags" attribute="Normal Text" lineEndContext="#stay"> <!-- Invalid Tag, do not highlight tags in these cases: * "?" or "," after tag name: <Tag ? ... <Tag< ? ... <Tag /* comment */ ? ... * Invalid delimiter after comment (without spaces): <Tag/* comment */# --> <RegExpr context="#pop" attribute="Symbol" String="<(?=\s*&name;(?:(<(?:\s*&mlComment;)*)?(?:\s*&mlComment;)*\s*[\?,]|(?:&mlComment;)+(?!&endTagName;|&baseName;|\{)))" /> <!-- Empty tag (element) --> <RegExpr context="ElementTagContent" attribute="Element Tag" String="<\s*>" beginRegion="Element" /> <!-- Detect Tags --> <RegExpr context="ElementTagFindType" attribute="Element Tag" String="&simpleTag;(?=&endTagName;)" beginRegion="Element" /> <RegExpr context="ComponentTagFindType" attribute="Component Tag" String="&tag;(?=&endTagName;)" beginRegion="ComponentElement" /> <!-- If a valid Tag was not detected --> <DetectChar context="#pop" attribute="Symbol" char="<" /> </context> <context name="FindTagsInTagContent" attribute="Normal Text" lineEndContext="#stay"> <!-- Empty tag (element) --> <RegExpr context="ElementTagContent" attribute="Element Tag" String="<\s*>" beginRegion="Element" /> <!-- Detect non-ASCII character in the tag name (component). This prevents highlighting as Element, tag names that don't start with a non-ASCII character. --> <RegExpr context="ComponentTagNonASCII" attribute="Component Tag" String="<\s*(?=(?:[a-z][a-z\d]*:)?(?:[a-z][a-z\d]*)?[^[:ascii:]])" beginRegion="ComponentElement" /> <!-- &simpleName; --> <!-- Element & component tags --> <RegExpr context="ElementTagFindType" attribute="Element Tag" String="&simpleTag;(?=[^\w\$\-\.:]|$|[\-\.]+(?:[^\w\$\-\.]|$)|:(?:[^a-zA-Z_\$]|$))" beginRegion="Element" /> <RegExpr context="ComponentTagFindType" attribute="Component Tag" String="&tag;" beginRegion="ComponentElement" /> </context> <!-- Highlight tag name with non-ASCII characters --> <context name="ComponentTagNonASCII" attribute="Normal Text" lineEndContext="#pop!ComponentTag" fallthrough="true" fallthroughContext="#pop!ComponentTag"> <RegExpr context="#pop!ComponentTagFindType" attribute="Component Tag" String="&name;" /> </context> <context name="FindEntityRefs" attribute="Normal Text" lineEndContext="#stay"> <RegExpr context="#stay" attribute="EntityRef" String="&entref;" /> </context> <!-- Type after the tag name. Ex: <C<number> /> --> <context name="ComponentTagFindType" attribute="Normal Text" lineEndContext="#pop!ComponentTag" fallthrough="true" fallthroughContext="#pop!ComponentTag"> <DetectChar context="#pop!TypeInsideTag" attribute="Symbol" char="<" /> </context> <context name="ElementTagFindType" attribute="Normal Text" lineEndContext="#pop!ElementTag" fallthrough="true" fallthroughContext="#pop!ElementTag"> <DetectChar context="#pop!TypeInsideTag" attribute="Symbol" char="<" /> </context> <!-- Type assertion after the tag name --> <context name="TypeInsideTag" attribute="Component Tag" lineEndContext="#stay"> <DetectChar context="#pop!ComponentTag" attribute="Symbol" char=">" /> <IncludeRules context="DefaultTypeInsideTag" /> </context> <context name="DefaultTypeInsideTag" attribute="Component Tag" lineEndContext="#stay"> <DetectChar context="TypeInsideTag-AngleBracket" attribute="Symbol" char="<" /> <DetectChar context="TypeInsideTag-CurlyBracket" attribute="Symbol" char="{" /> <DetectChar context="TypeInsideTag-SquareBracket" attribute="Symbol" char="[" /> <DetectChar context="TypeInsideTag-RoundBracket" attribute="Symbol" char="(" /> <IncludeRules context="AllComments" /> </context> <context name="TypeInsideTag-AngleBracket" attribute="Component Tag" lineEndContext="#stay"> <DetectChar context="#pop" attribute="Symbol" char=">" /> <IncludeRules context="DefaultTypeInsideTag" /> </context> <context name="TypeInsideTag-CurlyBracket" attribute="Component Tag" lineEndContext="#stay"> <DetectChar context="#pop" attribute="Symbol" char="}" /> <IncludeRules context="DefaultTypeInsideTag" /> </context> <context name="TypeInsideTag-SquareBracket" attribute="Component Tag" lineEndContext="#stay"> <DetectChar context="#pop" attribute="Symbol" char="]" /> <IncludeRules context="DefaultTypeInsideTag" /> </context> <context name="TypeInsideTag-RoundBracket" attribute="Component Tag" lineEndContext="#stay"> <DetectChar context="#pop" attribute="Symbol" char=")" /> <IncludeRules context="DefaultTypeInsideTag" /> </context> <!-- Inside the tag --> <context name="ElementTag" attribute="Normal Text" lineEndContext="#stay"> <Detect2Chars context="#pop" attribute="Element Tag" char="/" char1=">" endRegion="Element" /> <DetectChar context="#pop!ElementTagContent" attribute="Element Tag" char=">" /> <IncludeRules context="DefaultTag" /> </context> <context name="ComponentTag" attribute="Normal Text" lineEndContext="#stay"> <Detect2Chars context="#pop" attribute="Component Tag" char="/" char1=">" endRegion="ComponentElement" /> <DetectChar context="#pop!ComponentTagContent" attribute="Component Tag" char=">" /> <IncludeRules context="DefaultTag" /> </context> <context name="DefaultTag" attribute="Normal Text" lineEndContext="#stay"> <RegExpr context="Attribute" attribute="Attribute" String="&nameWithBound;" /> <IncludeRules context="FindEvaluatedCode" /> <IncludeRules context="AllComments" /> <RegExpr context="#stay" attribute="Error" String="\S+&name;|\S" /> </context> <!-- Tag content: <Tag> content </Tag> --> <context name="ElementTagContent" attribute="Tag Content Text" lineEndContext="#stay"> <RegExpr context="#pop" attribute="Element Tag" String="</\s*>" endRegion="Element" /> <!-- With component tag (error) --> <RegExpr context="ElementTagEnd" attribute="Element Tag" String="</\s*(&simpleName;|(?=[A-Z_\$]))" /> <IncludeRules context="DefaultTagContent" /> </context> <context name="ComponentTagContent" attribute="Tag Content Text" lineEndContext="#stay"> <RegExpr context="#pop" attribute="Component Tag" String="</\s*>" endRegion="ComponentElement" /> <RegExpr context="ComponentTagEnd" attribute="Component Tag" String="</\s*&name;" /> <IncludeRules context="DefaultTagContent" /> </context> <context name="DefaultTagContent" attribute="Tag Content Text" lineEndContext="#stay"> <IncludeRules context="FindTagsInTagContent" /> <IncludeRules context="FindEntityRefs" /> <IncludeRules context="FindEvaluatedCode" /> <DetectChar context="#stay" attribute="Error" char="<" /> </context> <context name="ElementTagEnd" attribute="Normal Text" lineEndContext="#stay"> <DetectChar context="#pop#pop" attribute="Element Tag" char=">" endRegion="Element" /> <RegExpr context="#stay" attribute="Error" String="\S" /> </context> <context name="ComponentTagEnd" attribute="Normal Text" lineEndContext="#stay"> <DetectChar context="#pop#pop" attribute="Component Tag" char=">" endRegion="ComponentElement" /> <RegExpr context="#stay" attribute="Error" String="\S" /> </context> <!-- Tag attribute --> <context name="Attribute" attribute="Normal Text" lineEndContext="#stay"> <RegExpr context="#pop" attribute="Error" String="\=(?=\s*/?>)" /> <DetectChar context="#pop!Value" attribute="Symbol" char="=" /> <IncludeRules context="FindEndTag" /> <DetectChar context="#pop" char="{" lookAhead="true" /> <!-- EvaluatedCode --> <IncludeRules context="AllComments" /> <RegExpr context="#stay" attribute="Attribute" String="&nameWithBound;" /> <RegExpr context="#stay" attribute="Error" String="\S+&name;|\S" /> </context> <context name="Value" attribute="Normal Text" lineEndContext="#stay"> <DetectChar context="#pop!ValueDQ" attribute="Value" char=""" /> <DetectChar context="#pop!ValueSQ" attribute="Value" char="'" /> <DetectChar context="#pop" char="{" lookAhead="true" /> <!-- EvaluatedCode --> <IncludeRules context="FindEndTag" /> <IncludeRules context="AllComments" /> <RegExpr context="#stay" attribute="Error" String="\S" /> </context> <context name="ValueDQ" attribute="Value" lineEndContext="#stay"> <DetectChar context="#pop" attribute="Value" char=""" /> <IncludeRules context="FindEntityRefs" /> </context> <context name="ValueSQ" attribute="Value" lineEndContext="#stay"> <DetectChar context="#pop" attribute="Value" char="'" /> <IncludeRules context="FindEntityRefs" /> </context> <context name="FindEndTag" attribute="Normal Text" lineEndContext="#stay"> <Detect2Chars context="#pop" char="/" char1=">" lookAhead="true" /> <DetectChar context="#pop" char=">" lookAhead="true" /> </context> <context name="FindEvaluatedCode" attribute="Normal Text" lineEndContext="#stay"> <!-- Find tags and send to the "EvaluatedCode" context --> <DetectChar context="EvaluatedCode-BeforeTag" attribute="Code Brackets" char="{" beginRegion="Code" /> </context> <context name="EvaluatedCode" attribute="Normal Text" lineEndContext="#stay"> <DetectChar context="#pop" attribute="Code Brackets" char="}" endRegion="Code" /> <IncludeRules context="Normal" /> </context> <context name="AllComments" attribute="Normal Text" lineEndContext="#stay"> <!-- TypeScript uses this for comments --> <IncludeRules context="FindComments##JavaScript" /> </context> </contexts> <itemDatas> <itemData name="Normal Text" defStyleNum="dsNormal" spellChecking="false" /> <itemData name="Comment" defStyleNum="dsComment" /> <itemData name="Tag Content Text" defStyleNum="dsNormal" /> <itemData name="Element Tag" defStyleNum="dsKeyword" spellChecking="false" /> <itemData name="Component Tag" defStyleNum="dsFunction" bold="1" spellChecking="false" /> <itemData name="Attribute" defStyleNum="dsOthers" spellChecking="false" /> <itemData name="Value" defStyleNum="dsString" spellChecking="false" /> <itemData name="EntityRef" defStyleNum="dsDecVal" spellChecking="false" /> <itemData name="Code Brackets" defStyleNum="dsVariable" spellChecking="false" /> <itemData name="Error" defStyleNum="dsError" spellChecking="false" /> <!-- itemDatas in JavaScript XML file --> <itemData name="Symbol" defStyleNum="dsOperator" /> <itemData name="ControlFlow" defStyleNum="dsControlFlow" spellChecking="false" /> <itemData name="Keyword" defStyleNum="dsKeyword" spellChecking="false" /> <itemData name="Reserved" defStyleNum="dsKeyword" italic="true" spellChecking="false" /> <itemData name="Module" defStyleNum="dsImport" spellChecking="false" /> <itemData name="Template" defStyleNum="dsVerbatimString" /> <itemData name="Substitution" defStyleNum="dsSpecialChar" spellChecking="false" /> <itemData name="Special Operators" defStyleNum="dsKeyword" spellChecking="false" /> </itemDatas></highlighting><general> <keywords casesensitive="1" /> <comments> <comment name="singleLine" start="//" /> <comment name="multiLine" start="/*" end="*/" /> </comments></general></language><!-- kate: replace-tabs off; tab-width 3; indent-width 3; remove-trailing-spaces mod; dynamic-word-wrap off; -->