<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language [
    <!-- alphabetic -->
    <!ENTITY alp "a-zA-Z">
    <!-- alphanumeric -->
    <!ENTITY aln "&alp;0-9">
    <!ENTITY id "\w[\w-]+">
    <!-- percent symbol, needs to be encoded inside an entity definition -->
    <!ENTITY perc "&#x0025;">

    <!ENTITY admonition_names "CAUTION|IMPORTANT|NOTE|TIP|WARNING">

    <!-- regular expression parts to identify anchors -->
    <!ENTITY anchor_mid "&id;(?:,.+?)?">
    <!ENTITY anchor_phrase "#\S(?:.*?\S)?#">

    <!-- block delimiters -->
    <!ENTITY block_dels_comment "/{4,}">
    <!ENTITY block_dels_normal "={4,}|_{4,}|\*{4,}|-{2}|&quot;{2}">
    <!ENTITY block_dels_pass "\+{4,}">
    <!ENTITY block_dels_verbatim "`{3}|-{4,}|\.{4,}">
    <!-- postfix/trailing part of block name -->
    <!ENTITY block_name_post "(?:[#&perc;].+)?\s*(?:,.*)?\]\s*$">
    <!-- block end delimiter, dynamic matching: "^%1\s*$" -->
    <!ENTITY block_end_del "^&perc;1\s*$">

    <!-- unicode character reference, decimal and hexadecimal -->
    <!ENTITY char_ref "&amp;#(?:\d{2,4}|x[\da-fA-F]{2,4});">

    <!-- email - inline -->
    <!ENTITY email "\w[\w.&perc;+-]*@[&aln;][&aln;.-]*\.[&alp;]{2,4}\b">

    <!-- link macro and mailto: -->
    <!ENTITY link_mailto "(?:link|mailto):[^:\s\[][^\s\[]*\[(?:\]|.*?[^\\]\])">

    <!-- macro -->
    <!ENTITY macro "(?:anchor|xref):&id;\[.*?\]|(?:btn|footnote(?:ref)?|kbd):\[.*?\]|pass:\w*\[.*?\]|(?:icon|image|menu):[^:].*?\[.*?\]|toc::\[\]">

    <!ENTITY list_marker "(?:\S.+::(?=\s|$)|(?:(?:\.+|\d+\.)|(?:-|\*+)(?:\s+\[[*x ]\])?)(?=\s+\S))">

    <!ENTITY table_option_delimiter "(?:(?:\d*\.)?\d+\+|\d+\*)?(?:[&lt;&gt;^]?\.?[&lt;&gt;^])?[adehlmsv]?\|">

    <!-- parts to build regular expressions to identify quoted (formatted) text
         E.g. emphasized, marked, strong. -->
    <!-- prefix/leading part -->
    <!ENTITY quoted_pre "(?&lt;=^|[^\w;:}])">
    <!ENTITY quoted_pre_pass "(?&lt;=^|\W)">
    <!-- central part -->
    <!ENTITY quoted "\S(?:.*?\S)??">
    <!-- postfix/trailing part -->
    <!ENTITY quoted_post "(?=\W|$)">
]>
<language author="Andreas Gratzer" extensions="*.ad;*.adoc;*.asciidoc" kateversion="5.0" mimetype="text/asciidoc" name="AsciiDoc" license="MIT" section="Markup" version="9">
    <highlighting>
        <list name="macro">
            <item>anchor</item>
            <item>btn</item>
            <item>footnote</item>
            <item>footnoteref</item>
            <item>icon</item>
            <item>image</item>
            <item>indexterm</item>
            <item>indexterm2</item>
            <item>kbd</item>
            <item>menu</item>
            <item>pass</item>
            <item>toc</item>
            <item>xref</item>
        </list>

        <contexts>
            <context name="start" attribute="Normal" lineEndContext="#stay" fallthrough="1" fallthroughContext="R section block">
                <!-- section title level 0 to 5 -->
                <RegExpr String="^(?:={1,6}|#{1,6})\s+(?=\S)" lookAhead="1" context="dispatch section main title" column="0"/>
                <IncludeRules context="R section inline"/>
            </context>

            <!-- attribute value definition, may span multiple lines -->
            <context name="attribute value" attribute="Normal" lineEndContext="#stay" lineEmptyContext="#pop">
                <!-- line with continuation -->
                <RegExpr String=".*?(?=\s+(?:\+\s+)?\\\s*$)" attribute="Attribute Value" context="continuation"/>
                <!-- line without continuation, terminates value definition -->
                <RegExpr String=".*" attribute="Attribute Value" context="#pop"/>
            </context>
            <!-- inline attribute value definition -->
            <context name="attribute value inline" attribute="Attribute Value" lineEndContext="#stay">
                <!-- the leading `:` is part of the definition syntax and should not be highlighted as value -->
                <DetectChar char=":" attribute="Attribute" context="attribute value inline L2"/>
                <DetectChar char="}" attribute="Attribute" context="#pop"/>
            </context>
            <context name="attribute value inline L2" attribute="Attribute Value" lineEndContext="#stay">
                <DetectChar char="}" attribute="Attribute" context="#pop#pop"/>
            </context>

            <!-- backlash, may function as an escape -->
            <context name="backlash" attribute="Normal" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop">
                <!-- attribute usage
                     formatted/quoted text
                     replacement of apostrophe
                     table separator (default)
                     anchor, consuming leading char will make anchor matches fail
                     cross reference
                     indexterm, consuming leading char will make matches fail
                -->
                <!-- replacement (besides apostrophe -->
                <Detect2Chars char="&lt;" char1="-" attribute="Normal" context="#pop"/>
                <Detect2Chars char="&lt;" char1="=" attribute="Normal" context="#pop"/>
                <AnyChar String="_#`+*~^'|{[&lt;(" attribute="Normal" context="#pop"/>
                <Detect2Chars char="-" char1="-" attribute="Normal" context="#pop"/>
                <Detect2Chars char="-" char1="&gt;" attribute="Normal" context="#pop"/>
                <Detect2Chars char="=" char1="&gt;" attribute="Normal" context="#pop"/>
                <StringDetect String="..." attribute="Normal" context="#pop"/>
                <!-- email - inline, needs to be ordered after mailto: -->
                <!-- link and mailto macros, note that ftp, irc, http(s) don't match with leading `\` anyway -->
                <RegExpr String="&email;|&link_mailto;|&char_ref;" attribute="Normal" context="#pop"/>
                <!-- macro -->
                <keyword String="macro" attribute="Normal" context="#pop"/>
            </context>

            <context name="block title" attribute="Block Title" lineEndContext="#pop">
                <IncludeRules context="R title"/>
            </context>

            <context name="comment" attribute="Comment" lineEndContext="#stay" lineEmptyContext="#pop">
                <DetectSpaces attribute="Comment"/>
                <RegExpr String="^(&block_dels_comment;)\s*$" attribute="Comment" context="#pop!comment delimited" beginRegion="comment" column="0"/>
                <IncludeRules context="R anchor"/>
                <IncludeRules context="R block title"/>
                <IncludeRules context="##Comments"/>
                <DetectIdentifier attribute="Comment"/>
            </context>
            <context name="comment delimited" attribute="Comment" lineEndContext="#stay">
                <DetectSpaces attribute="Comment"/>
                <RegExpr String="&block_end_del;" dynamic="true" attribute="Comment" context="#pop" endRegion="comment" column="0"/>
                <IncludeRules context="##Comments" />
                <DetectIdentifier attribute="Comment"/>
            </context>
            <context name="comment single-line" attribute="Comment" lineEndContext="#pop">
                <DetectSpaces attribute="Comment"/>
                <IncludeRules context="##Comments" />
                <DetectIdentifier attribute="Comment"/>
            </context>

            <!-- continuation, both for normal text and attribute value definition
                 The allowed pattern must already by validated.
                 Here only the possible characters are highlighted. -->
            <context name="continuation" attribute="Normal" lineEndContext="#pop">
                <AnyChar String="+\" attribute="Control"/>
            </context>

            <context name="main title" attribute="Main Title" lineEndContext="#pop!section L0">
                <IncludeRules context="R title"/>
            </context>

            <context name="normal" attribute="Normal" lineEndContext="#stay" lineEmptyContext="#pop">
                <RegExpr String="^(-{2}|&block_dels_normal;)\s*$" attribute="Delimiter" context="#pop!normal delimited" beginRegion="block" column="0"/>
                <IncludeRules context="R block title"/>
                <!-- shared rules includes anchor rules, so we do not need to include that separately -->
                <IncludeRules context="R shared"/>
                <IncludeRules context="R normal"/>
            </context>
            <context name="normal delimited" attribute="Normal" lineEndContext="#stay">
                <RegExpr String="&block_end_del;" dynamic="true" attribute="Delimiter" context="#pop" endRegion="block" column="0"/>
                <IncludeRules context="R admonition"/>
                <IncludeRules context="R block"/>
                <!-- shared rules includes anchor rules, so we do not need to include that separately -->
                <IncludeRules context="R shared"/>
                <IncludeRules context="R normal"/>
            </context>

            <context name="passthrough" attribute="Passthrough" lineEndContext="#stay" lineEmptyContext="#pop">
                <DetectSpaces attribute="Passthrough"/>
                <IncludeRules context="R include"/>
                <DetectIdentifier attribute="Passthrough"/>
                <RegExpr String="^(&block_dels_pass;)\s*$" attribute="Delimiter" context="#pop!passthrough delimited" beginRegion="block" column="0"/>
                <IncludeRules context="R anchor"/>
                <IncludeRules context="R block title"/>
            </context>
            <context name="passthrough delimited" attribute="Passthrough" lineEndContext="#stay">
                <RegExpr String="&block_end_del;" dynamic="true" attribute="Delimiter" context="#pop" endRegion="block" column="0"/>
                <IncludeRules context="R include"/>
            </context>

            <context name="dispatch section main title" attribute="Normal" lineEndContext="#stay">
                <IncludeRules context="dispatch section title L1-5"/>
                <!-- main title, first level 0 section title -->
                <AnyChar String="=#" attribute="Main Title" context="#pop!main title" beginRegion="section" column="0"/>
            </context>

            <context name="dispatch section title L0-5" attribute="Normal" lineEndContext="#stay">
                <IncludeRules context="dispatch section title L1-5"/>
                <AnyChar String="=#" attribute="Section Title" context="#pop!section title L0" beginRegion="section" endRegion="section" column="0"/>
            </context>
            <context name="dispatch section title L1-5" attribute="Normal" lineEndContext="#stay">
                <IncludeRules context="dispatch section title L2-5"/>
                <Detect2Chars char="=" char1="=" attribute="Section Title" context="#pop!section title L1" beginRegion="section" column="0"/>
                <Detect2Chars char="#" char1="#" attribute="Section Title" context="#pop!section title L1" beginRegion="section" column="0"/>
            </context>
            <context name="dispatch section title L2-5" attribute="Normal" lineEndContext="#stay">
                <IncludeRules context="dispatch section title L3-5"/>
                <StringDetect String="===" attribute="Section Title" context="#pop!section title L2" beginRegion="section" column="0"/>
                <StringDetect String="###" attribute="Section Title" context="#pop!section title L2" beginRegion="section" column="0"/>
            </context>
            <context name="dispatch section title L3-5" attribute="Normal" lineEndContext="#stay">
                <IncludeRules context="dispatch section title L4-5"/>
                <StringDetect String="====" attribute="Section Title" context="#pop!section title L3" beginRegion="section" column="0"/>
                <StringDetect String="####" attribute="Section Title" context="#pop!section title L3" beginRegion="section" column="0"/>
            </context>
            <context name="dispatch section title L4-5" attribute="Normal" lineEndContext="#stay">
                <IncludeRules context="dispatch section title L5"/>
                <StringDetect String="=====" attribute="Section Title" context="#pop!section title L4" beginRegion="section" column="0"/>
                <StringDetect String="#####" attribute="Section Title" context="#pop!section title L4" beginRegion="section" column="0"/>
            </context>
            <context name="dispatch section title L5" attribute="Normal" lineEndContext="#stay">
                <StringDetect String="======" attribute="Section Title" context="#pop!section title L5" beginRegion="section" column="0"/>
                <StringDetect String="######" attribute="Section Title" context="#pop!section title L5" beginRegion="section" column="0"/>
            </context>

            <context name="section L0" attribute="Normal" lineEndContext="#stay" fallthrough="1" fallthroughContext="R section block">
                <RegExpr String="^(?:={1,6}|#{1,6})\s+(?=\S)" lookAhead="1" context="dispatch section title L0-5" column="0"/>
                <IncludeRules context="section L5"/>
            </context>

            <context name="section L1" attribute="Normal" lineEndContext="#stay" fallthrough="1" fallthroughContext="R section block">
                <RegExpr String="^(?:={3,6}|#{3,6})\s+(?=\S)" lookAhead="1" context="dispatch section title L2-5" column="0"/>
                <IncludeRules context="section L5"/>
            </context>

            <context name="section L2" attribute="Normal" lineEndContext="#stay" fallthrough="1" fallthroughContext="R section block">
                <RegExpr String="^(?:={4,6}|#{4,6})\s+(?=\S)" lookAhead="1" context="dispatch section title L3-5" column="0"/>
                <IncludeRules context="section L5"/>
            </context>

            <context name="section L3" attribute="Normal" lineEndContext="#stay" fallthrough="1" fallthroughContext="R section block">
                <RegExpr String="^(?:={5,6}|#{5,6})\s+(?=\S)" lookAhead="1" context="dispatch section title L4-5" column="0"/>
                <IncludeRules context="section L5"/>
            </context>

            <context name="section L4" attribute="Normal" lineEndContext="#stay" fallthrough="1" fallthroughContext="R section block">
                <RegExpr String="^(?:={6}|#{6})\s+(?=\S)" lookAhead="1" context="dispatch section title L5" column="0"/>
                <IncludeRules context="section L5"/>
            </context>

            <context name="section L5" attribute="Normal" lineEndContext="#stay" fallthrough="1" fallthroughContext="R section block">
                <RegExpr String="^(?:={1,6}|#{1,6})\s+\S" lookAhead="1" context="#pop" endRegion="section" column="0"/>
                <IncludeRules context="R section inline"/>
            </context>

            <context name="section title L0" attribute="Section Title" lineEndContext="#pop">
                <IncludeRules context="R title"/>
            </context>

            <context name="section title L1" attribute="Section Title" lineEndContext="#pop!section L1">
                <IncludeRules context="R title"/>
            </context>

            <context name="section title L2" attribute="Section Title" lineEndContext="#pop!section L2">
                <IncludeRules context="R title"/>
            </context>

            <context name="section title L3" attribute="Section Title" lineEndContext="#pop!section L3">
                <IncludeRules context="R title"/>
            </context>

            <context name="section title L4" attribute="Section Title" lineEndContext="#pop!section L4">
                <IncludeRules context="R title"/>
            </context>

            <context name="section title L5" attribute="Section Title" lineEndContext="#pop!section L5">
                <IncludeRules context="R title"/>
            </context>

            <context name="table" attribute="Normal" lineEndContext="#stay">
                <RegExpr String="&block_end_del;" dynamic="true" attribute="Delimiter" context="#pop" endRegion="block" column="0"/>
                <!-- `|` with prefix for alignment, style etc. -->
                <RegExpr String="(?&lt;=^|\s)&table_option_delimiter;" attribute="Delimiter"/>
                <!-- simple `|` without alignment, style etc. -->
                <DetectChar char="|" attribute="Delimiter"/>
                <IncludeRules context="R shared"/>
                <IncludeRules context="R normal"/>
            </context>

            <context name="verbatim" attribute="Verbatim" lineEndContext="#stay">
                <RegExpr String="^(-{2}|&block_dels_verbatim;)\s*$" attribute="Delimiter" context="#pop!verbatim delimited" beginRegion="block" column="0"/>
                <IncludeRules context="R anchor"/>
                <RegExpr String="^(\[\w+[^,\]]*(,[^,\]]*)*\]\s*)+$" attribute="Preprocessor" column="0"/>
                <IncludeRules context="R block title"/>
                <IncludeRules context="R comment"/>
                <IncludeRules context="R include"/>
                <RegExpr String="^.*" attribute="Verbatim" context="#pop!verbatim paragraph" column="0"/>
            </context>
            <context name="verbatim delimited" attribute="Verbatim" lineEndContext="#stay">
                <RegExpr String="&block_end_del;" dynamic="true" attribute="Delimiter" context="#pop" endRegion="block" column="0"/>
                <IncludeRules context="R include"/>
            </context>
            <context name="verbatim paragraph" attribute="Verbatim" lineEndContext="#stay" lineEmptyContext="#pop">
                <IncludeRules context="R include"/>
            </context>

            <!-- contexts to be used for IncludeRules only -->

            <context name="R normal" attribute="Normal" lineEndContext="#stay">
                <!-- Regex which allows to quickly consume text that is not
                    - macro
                    - continuation
                    - index term
                    - link
                    - replacement
                    - preprocessor
                    - formatted text
                    - table delimiter

                maanchor:anchor-id[Macro Anchor]
                ^ Normal
                  ^ Macro

                bla__bla__bla
                ^ Normal
                   ^ Emphasized
                          ^ Normal

                For some reason, Asciidoctor recognizes emails with leading : or / but does not render them as link

                /example@mail.com
                ^ Normal

                example@mail.com
                ^ Link
                -->
                <RegExpr String="([:/]&email;|(?!&macro;|link:|mailto:|(?:ftp|https?|irc)://|&char_ref;|indexterm2?:\[.+?\]|[\\+|\[{~^]|__|##|\([CR]\)|\(TM\)|\.\.\.|&lt;[-=&lt;]|--|->|=>|``\*?_?|\*\*_?|\(\(|\s+[[+]|\s&table_option_delimiter;|(?&lt;=[^&alp;;:}])_|&quoted_pre;(`\*?_?|\*_?|#)|(?&lt;=[&alp;])'(?=[&alp;])|&email;).)++" attribute="Normal"/>
            </context>

            <context name="R admonition" attribute="Normal" lineEndContext="#stay">
                <!-- admonition - simple form, block form is part of block rules -->
                <RegExpr String="^(?:&admonition_names;):(?=\s+\S)" attribute="Preprocessor" context="normal" column="0"/>
            </context>

            <context name="R anchor" attribute="Normal" lineEndContext="#stay">
                <!-- shorthand form at line start -->
                <!-- bibliographic anchor -->
                <!-- normal form -->
                <!-- shorthand form inline -->
                <RegExpr String="^\[#&anchor_mid;\](?:&anchor_phrase;|\s*$)|\[{3}&anchor_mid;\]{3}|\[{2}&anchor_mid;\]{2}|(?&lt;=\S\s)\s*\[\s*#&anchor_mid;\s*\]&anchor_phrase;" attribute="Anchor"/>
            </context>

            <context name="R attribute" attribute="Normal" lineEndContext="#stay">
                <!-- attribute definition without value / unset attribute -->
                <RegExpr String="^:!?&id;!?:$" attribute="Attribute" column="0"/>
                <!-- attribute definition with value -->
                <RegExpr String="^:!?&id;!?:\s(?=\S)" attribute="Attribute" context="attribute value" column="0"/>
                <!-- attribute inline definition -->
                <RegExpr String="\{set:&id;(?=(?::.*)?\})" minimal="true" attribute="Attribute" context="attribute value inline"/>
                <IncludeRules context="R attribute usage"/>
            </context>

            <context name="R attribute usage" attribute="Normal" lineEndContext="#stay">
                <RegExpr String="\{&id;\}" attribute="Attribute"/>
            </context>

            <context name="R block" attribute="Normal" lineEndContext="#stay">
                <IncludeRules context="R block title"/>
                <IncludeRules context="R block without title"/>
            </context>

            <context name="R block without title" attribute="Normal" lineEndContext="#stay">
                <!-- name matching -->
                <RegExpr String="^\[(?:&admonition_names;)&block_name_post;|^\[(?:example|quote|sidebar|verse)&block_name_post;" attribute="Preprocessor" context="normal" column="0"/>
                <RegExpr String="^\[(?:pass|stem)&block_name_post;" attribute="Preprocessor" context="passthrough" column="0"/>
                <RegExpr String="^\[(?:listing|literal|source)&block_name_post;" attribute="Preprocessor" context="verbatim" column="0"/>

                <!-- delimiter matching -->
                <RegExpr String="^(&block_dels_normal;)\s*$" attribute="Delimiter" context="normal delimited" beginRegion="block" column="0"/>
                <RegExpr String="^(&block_dels_pass;)\s*$" attribute="Delimiter" context="passthrough delimited" beginRegion="block" column="0"/>
                <RegExpr String="^(\|={3,})\s*$" attribute="Delimiter" context="table" beginRegion="block" column="0"/>
                <RegExpr String="^(&block_dels_verbatim;)\s*$" attribute="Delimiter" context="verbatim delimited" beginRegion="block" column="0"/>
            </context>

            <context name="R block title" attribute="Normal" lineEndContext="#stay">
                <!-- not more than 3 leading dots followed by a non-dot, otherwise it would conflict with the delimited literal block -->
                <RegExpr String="^\.{1,3}(?=[^\.\s])" attribute="Block Title" context="block title" column="0"/>
            </context>

            <context name="R comment" attribute="Normal" lineEndContext="#stay">
                <!-- comment - multi-line, named block -->
                <RegExpr String="^\[comment&block_name_post;" attribute="Preprocessor" context="comment" column="0"/>
                <!-- comment - multi-line, delimited block -->
                <RegExpr String="^(&block_dels_comment;)\s*$" attribute="Comment" context="comment delimited" beginRegion="comment" column="0"/>
                <!-- comment - single line -->
                <RegExpr String="^/{2}(?:[^/]|$)" attribute="Comment" context="comment single-line" column="0"/>
            </context>

            <context name="R formatted" attribute="Normal" lineEndContext="#stay">
                <!-- custom style, e.g. [underline]#underlined text# -->
                <RegExpr String="(?&lt;=^|\W)\[[^\]]+?\]([#_`*]{1,2})&quoted;\g1&quoted_post;" attribute="Preprocessor"/>

                <!-- combined highlighting must be ordered before simple highlighting -->

                <!-- emphasized monospaced strong unconstrained - must be ordered before constrained -->
                <!-- emphasized monospaced strong - constrained must be ordered after unconstrained -->
                <RegExpr String="`{2}\*_.*?_\*`{2}|&quoted_pre;`\*_&quoted;_\*`&quoted_post;" attribute="Emphasized Monospaced Strong"/>

                <!-- emphasized strong unconstrained - must be ordered before constrained -->
                <!-- emphasized strong constrained - must be ordered after unconstrained -->
                <RegExpr String="\*{2}_.*?_\*{2}|&quoted_pre;\*_&quoted;_\*&quoted_post;" attribute="Emphasized Strong"/>

                <!-- monospaced strong unconstrained - must be ordered before constrained -->
                <!-- monospaced strong constrained - must be ordered after unconstrained -->
                <RegExpr String="`{2}\*.*?\*`{2}|&quoted_pre;`\*&quoted;\*`&quoted_post;" attribute="Monospaced Strong"/>

                <!-- emphasized monospaced unconstrained - must be ordered before constrained -->
                <!-- emphasized monospaced constrained - must be ordered after unconstrained -->
                <RegExpr String="`{2}_.*?_`{2}|&quoted_pre;`_&quoted;_`&quoted_post;" attribute="Emphasized Monospaced"/>

                <!-- strong unconstrained - must be ordered before constrained -->
                <!-- strong constrained - must be ordered after unconstrained -->
                <RegExpr String="\*{2}[^*].*?\*{2}|&quoted_pre;\*&quoted;\*&quoted_post;" attribute="Strong"/>

                <!-- emphasized unconstrained - must be ordered before constrained -->
                <!-- emphasized constrained - must be ordered after unconstrained
                     Can't use &quoted_pre; as that excludes \w which excludes `_` too. -->
                <RegExpr String="_{2}[^_].*?_{2}|(?&lt;=^|[^&alp;;:}])_&quoted;_&quoted_post;" attribute="Emphasized"/>

                <IncludeRules context="R marked"/>
                <IncludeRules context="R monospaced"/>

                <!-- subscript -->
                <RegExpr String="~\S+~" minimal="true" attribute="Subscript"/>
                <!-- superscript -->
                <RegExpr String="\^\S+\^" minimal="true" attribute="Superscript"/>
            </context>

            <context name="R include" attribute="Normal" lineEndContext="#stay">
                <RegExpr String="^include::.*\[.*?\](?=\s*$)" attribute="Preprocessor" column="0"/>
            </context>

            <context name="R macro" attribute="Normal" lineEndContext="#stay">
                <RegExpr String="&macro;" attribute="Preprocessor"/>
            </context>

            <context name="R marked" attribute="Normal" lineEndContext="#stay">
                <!-- marked unconstrained - must be ordered before constrained -->
                <!-- marked constrained - must be ordered after unconstrained -->
                <RegExpr String="#{2}.+?#{2}|&quoted_pre;#&quoted;#&quoted_post;" attribute="Marked"/>
            </context>

            <context name="R monospaced" attribute="Normal" lineEndContext="#stay">
                <!-- monospaced unconstrained - must be ordered before constrained -->
                <!-- monospaced constrained - must be ordered after unconstrained -->
                <RegExpr String="`{2}[^`].*?`{2}|&quoted_pre;`&quoted;`&quoted_post;" attribute="Monospaced"/>
            </context>

            <!-- replacements -->
            <context name="R replacement" attribute="Normal" lineEndContext="#stay">
                <!-- copyright -->
                <StringDetect String="(C)" attribute="Replacement"/>
                <!-- registered -->
                <StringDetect String="(R)" attribute="Replacement"/>
                <!-- trademark -->
                <StringDetect String="(TM)" attribute="Replacement"/>
                <!-- apostrophe, only when between alphabetic characters -->
                <RegExpr String="(?&lt;=[&alp;])'(?=[&alp;])" attribute="Replacement"/>
                <!-- ellipses -->
                <StringDetect String="..." attribute="Replacement"/>
                <!-- mdash -->
                <Detect2Chars char="-" char1="-" attribute="Replacement"/>
                <!-- left single arrow -->
                <Detect2Chars char="&lt;" char1="-" attribute="Replacement"/>
                <!-- right single arrow -->
                <Detect2Chars char="-" char1="&gt;" attribute="Replacement"/>
                <!-- left double arrow -->
                <Detect2Chars char="&lt;" char1="=" attribute="Replacement"/>
                <!-- right double arrow -->
                <Detect2Chars char="=" char1="&gt;" attribute="Replacement"/>
                <!-- unicode character reference -->
                <RegExpr String="&char_ref;" attribute="Replacement"/>
            </context>

            <context name="R section inline" attribute="Normal" lineEndContext="#stay">
                <!-- literal paragraph started by a line with leading spaces -->
                <RegExpr String="^\s+(?!&list_marker;)\S.*" attribute="Verbatim" context="verbatim paragraph" column="0"/>
                <IncludeRules context="R block"/>
                <IncludeRules context="R anchor"/>
                <IncludeRules context="R comment"/>
                <IncludeRules context="R media"/>
                <IncludeRules context="R preprocessor"/>
                <IncludeRules context="R horizontal rules and page break"/>
            </context>

            <!-- first line of a section block -->
            <context name="R section block" attribute="Normal" lineEndContext="#pop!section block continuation" lineEmptyContext="#pop">
                <IncludeRules context="R callout"/>
                <RegExpr String="^\+\s*$" attribute="Control" context="#pop" column="0"/>
                <IncludeRules context="R admonition"/>
                <IncludeRules context="R block"/>
                <IncludeRules context="R shared"/>
                <IncludeRules context="R empty"/>
                <IncludeRules context="R normal"/>
            </context>

            <!-- callout as being used below a source code block -->
            <context name="R callout" attribute="Normal" lineEndContext="#stay" lineEmptyContext="#pop">
                <RegExpr String="^&lt;(?:\.|\d+)&gt;(?=\s+\S)" attribute="Callout" context="#pop!callout" column="0"/>
            </context>
            <context name="callout" attribute="Normal" lineEndContext="#stay" lineEmptyContext="#pop">
                <IncludeRules context="R callout"/>
                <IncludeRules context="section block continuation"/>
            </context>

            <!-- line 2 and following of a section block -->
            <context name="section block continuation" attribute="Normal" lineEndContext="#stay" lineEmptyContext="#pop">
                <RegExpr String="^\+\s*$" attribute="Control" context="#pop" column="0"/>
                <IncludeRules context="R block without title"/>
                <IncludeRules context="R shared"/>
                <IncludeRules context="R empty"/>
                <IncludeRules context="R normal"/>
            </context>

            <context name="R empty" attribute="Normal" lineEndContext="#stay">
                <RegExpr String="^\s+$" attribute="Normal" context="#pop" column="0"/>
            </context>

            <context name="R shared" attribute="Normal" lineEndContext="#stay">
                <!-- the escaped forms must be ordered before the not escaped forms -->
                <DetectChar char="\" attribute="Normal" context="backlash"/>

                <!-- passthrough - inline, must be ordered before other rules
                     The macro form pass: is part of "R macro" context -->
                <RegExpr String="&quoted_pre_pass;(\+{1,3})&quoted;\g1&quoted_post;" attribute="Passthrough"/>

                <IncludeRules context="R anchor"/>
                <IncludeRules context="R attribute"/>
                <IncludeRules context="R comment"/>
                <IncludeRules context="R include"/>
                <IncludeRules context="R macro"/>

                <!-- counter and counter2 -->
                <RegExpr String="\{counter2?:\s*&id;\s*(?::\s*(?:\d+|[&alp;])\s*)?\}" minimal="true" attribute="Attribute"/>

                <!-- horizontal rules and page break -->
                <!-- to enable highlighting of the horizontal rules using "- - -" or "* * *",
                     keep this before the checklist and unnumbered list definition -->
                <IncludeRules context="R horizontal rules and page break"/>

                <!-- cross reference -->
                <RegExpr String="&lt;&lt;[^&lt;\s].*?&gt;&gt;" attribute="Link"/>

                <!-- index term -->
                <RegExpr String="\({3}.+?\){3}|\({2}.+?\){2}|indexterm2?:\[.+?\]" attribute="Preprocessor"/>

                <!-- marker for description list -->
                <!-- marker for numbered list -->
                <!-- marker for checklist and bulleted/unnumbered list
                     To enable highlighting of the horizontal rules using "- - -" or "* * *",
                     keep this after the horizontal rules definition -->
                <RegExpr String="^\s*&list_marker;" attribute="List Marker" column="0"/>

                <!-- media - block format -->
                <IncludeRules context="R media"/>

                <!-- links -->
                <RegExpr String="(?&lt;=^|[\s\[\]();&lt;&gt;])(?:ftp|https?|irc)://[^\s\[]*?(?:\[\]|\[.*?[^\\]\]|(?=(?:[\[\]]|[\.,;:]??(?:\s|$))))|&link_mailto;|&email;" attribute="Link"/>

                <!-- preprocessor -->
                <!-- general meta data attribute list - must be ordered after other rules matching for lines of the form of [some content] -->
                <IncludeRules context="R preprocessor"/>

                <!-- continuation `+`, both at end of line and on a line on its own -->
                <RegExpr String="(?:^|\s)\s*\+\s*$" lookAhead="true" attribute="Normal" context="continuation"/>

                <!-- formatted/quoted must be ordered after unnumbered list -->
                <IncludeRules context="R formatted"/>
                <!-- replacements are done only if nothing else matched -->
                <IncludeRules context="R replacement"/>
            </context>

            <context name="R media" attribute="Normal" lineEndContext="#stay">
                <RegExpr String="^(?:audio|image|video)::.*\[.*?\](?=\s*$)" attribute="Preprocessor" column="0"/>
            </context>

            <context name="R preprocessor" attribute="Normal" lineEndContext="#stay">
                <RegExpr String="^ifn?def::&id;(?:[,\+]&id;)*\[.*\]|^ifeval::\[.*\]|^endif::(?:&id;)?\[\]|^\[[^\s\[].*\](?=\s*$)" attribute="Preprocessor" column="0"/>
            </context>

            <context name="R horizontal rules and page break" attribute="Normal" lineEndContext="#stay">
                <RegExpr String="^(?:'{3}|-{3}|\*{3}|- - -|\* \* \*|&lt;{3})\s*$" attribute="Control" column="0"/>
            </context>

            <!-- common rules for main title, section title, block title -->
            <context name="R title" attribute="Normal" lineEndContext="#stay">
                <DetectSpaces/>
                <DetectIdentifier/>
                <!-- the escaped forms must be ordered before the not escaped forms -->
                <DetectChar char="\" attribute="Section Title" context="backlash"/>
                <IncludeRules context="R anchor"/>
                <IncludeRules context="R attribute usage"/>
                <IncludeRules context="R marked"/>
                <IncludeRules context="R monospaced"/>
            </context>
        </contexts>

        <itemDatas>
            <itemData name="Anchor" defStyleNum="dsFunction"/>
            <itemData name="Attribute" defStyleNum="dsVariable"/>
            <itemData name="Attribute Value" defStyleNum="dsVariable" italic="true"/>
            <itemData name="Block Title" defStyleNum="dsString" italic="true"/>
            <itemData name="Callout" defStyleNum="dsNormal" bold="true" underline="true"/>
            <itemData name="Comment" defStyleNum="dsComment"/>
            <itemData name="Control" defStyleNum="dsControlFlow" bold="true" underline="true"/>
            <itemData name="Delimiter" defStyleNum="dsPreprocessor" bold="true"/>
            <itemData name="Emphasized" defStyleNum="dsNormal" italic="true"/>
            <itemData name="Emphasized Monospaced" defStyleNum="dsDocumentation" italic="true"/>
            <itemData name="Emphasized Monospaced Strong" defStyleNum="dsDocumentation" bold="true" italic="true"/>
            <itemData name="Emphasized Strong" defStyleNum="dsNormal" bold="true" italic="true"/>
            <itemData name="Link" defStyleNum="dsVariable" underline="true"/>
            <itemData name="List Marker" defStyleNum="dsNormal" bold="true"/>
            <itemData name="Main Title" defStyleNum="dsNormal" bold="true"/>
            <itemData name="Marked" defStyleNum="dsFloat"/>
            <itemData name="Monospaced" defStyleNum="dsDocumentation"/>
            <itemData name="Monospaced Strong" defStyleNum="dsDocumentation" bold="true"/>
            <itemData name="Normal" defStyleNum="dsNormal"/>
            <itemData name="Passthrough" defStyleNum="dsSpecialString"/>
            <itemData name="Preprocessor" defStyleNum="dsPreprocessor"/>
            <itemData name="Replacement" defStyleNum="dsNormal" bold="true" underline="true"/>
            <itemData name="Section Title" defStyleNum="dsString" bold="true"/>
            <itemData name="Strong" defStyleNum="dsNormal" bold="true"/>
            <itemData name="Subscript" defStyleNum="dsNormal" underline="true"/>
            <itemData name="Superscript" defStyleNum="dsNormal" bold="true" underline="true"/>
            <itemData name="Verbatim" defStyleNum="dsDocumentation"/>
        </itemDatas>
    </highlighting>

    <general>
        <comments>
            <comment name="singleLine" start="//"/>
            <comment name="multiLine" start="////" end="////" region="comment"/>
        </comments>
        <keywords casesensitive="1"/>
    </general>
</language>
<!-- kate: replace-tabs on; tab-width 4; indent-width 4; -->
