development.docbook 179 KB
Newer Older
1
<!-- auto-generate scripting documentation (kwrite-devel@kde.org Re: [kate] doc/kate: document most of the new scripts in 4.10) -->
2
3
4
5
6
7
8
9
10
11
12
13
14
<chapter id="dev">
<chapterinfo>
<authorgroup>
<author>&TC.Hollingsworth; &TC.Hollingsworth.mail;</author>
<!-- TRANS:ROLES_OF_TRANSLATORS -->
</authorgroup>
</chapterinfo>
<title>Extending &katepart;</title>

<sect1 id="dev-intro">
<title>Introduction</title>

<para>Like any advanced text editor component, &katepart; offers a variety of
15
ways to extend its functionality.  You can <link linkend="dev-scripting">write
16
simple scripts to add functionality with &javascript;</link>.
17
Finally, once you have extended &katepart;, you are
Yuri Chornoivan's avatar
Yuri Chornoivan committed
18
welcome to <ulink url="https://kate-editor.org/join-us/">join us</ulink>
19
20
21
22
and share your enhancements with the world!</para>

</sect1>

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<sect1 id="highlight">
<title>Working with Syntax Highlighting</title>

<sect2 id="highlight-overview">

<title>Overview</title>

<para>Syntax Highlighting is what makes the editor automatically
display text in different styles/colors, depending on the function of
the string in relation to the purpose of the file.  In program source
code for example, control statements may be rendered bold, while data
types and comments get different colors from the rest of the
text. This greatly enhances the readability of the text, and thus
helps the author to be more efficient and productive.</para>

<mediaobject>
<imageobject><imagedata format="PNG" fileref="highlighted.png"/></imageobject>
40
<textobject><phrase>A C++ function, rendered with syntax
41
highlighting.</phrase></textobject>
42
<caption><para>A C++ function, rendered with syntax highlighting.</para>
43
44
45
46
47
</caption>
</mediaobject>

<mediaobject>
<imageobject><imagedata format="PNG" fileref="unhighlighted.png"/></imageobject>
48
<textobject><phrase>The same C++ function, without
49
highlighting.</phrase></textobject>
50
<caption><para>The same C++ function, without highlighting.</para></caption>
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
</mediaobject>

<para>Of the two examples, which is easiest to read?</para>

<para>&kappname; comes with a flexible, configurable and capable system
for doing syntax highlighting, and the standard distribution provides
definitions for a wide range of programming, scripting and markup
languages and other text file formats. In addition you can
provide your own definitions in simple &XML; files.</para>

<para>&kappname; will automatically detect the right syntax rules when you
open a file, based on the &MIME; Type of the file, determined by its
extension, or, if it has none, the contents. Should you experience a
bad choice, you can manually set the syntax to use from the
<menuchoice><guimenu>Tools</guimenu><guisubmenu>Highlighting
</guisubmenu></menuchoice> menu.</para>

<para>The styles and colors used by each syntax highlight definition
can be configured using the <link
linkend="prefcolors-highlighting-text-styles">Highlighting Text Styles</link> tab of the
<link linkend="config-dialog">Config Dialog</link>, while the &MIME; Types and
file extensions it should be used for are handled by the <link
linkend="pref-open-save-modes-filetypes">Modes &amp; Filetypes</link>
tab.</para>

<note>
<para>Syntax highlighting is there to enhance the readability of
correct text, but you cannot trust it to validate your text. Marking
text for syntax is difficult depending on the format you are using,
and in some cases the authors of the syntax rules will be proud if 98%
of text gets correctly rendered, though most often you need a rare
style to see the incorrect 2%.</para>
</note>

</sect2>

<sect2 id="katehighlight-system">

<title>The &kappname; Syntax Highlight System</title>

<para>This section will discuss the &kappname; syntax highlighting
mechanism in more detail. It is for you if you want to know about
it, or if you want to change or create syntax definitions.</para>

<sect3 id="katehighlight-howitworks">

<title>How it Works</title>

<para>Whenever you open a file, one of the first things the &kappname;
editor does is detect which syntax definition to use for the
file. While reading the text of the file, and while you type away in
it, the syntax highlighting system will analyze the text using the
rules defined by the syntax definition and mark in it where different
contexts and styles begin and end.</para>

<para>When you type in the document, the new text is analyzed and marked on the
fly, so that if you delete a character that is marked as the beginning or end
of a context, the style of surrounding text changes accordingly.</para>

<para>The syntax definitions used by the &kappname; Syntax Highlighting System are
&XML; files, containing
<itemizedlist>
<listitem><para>Rules for detecting the role of text, organized into context blocks</para></listitem>
<listitem><para>Keyword lists</para></listitem>
<listitem><para>Style Item definitions</para></listitem>
</itemizedlist>
</para>

<para>When analyzing the text, the detection rules are evaluated in
the order in which they are defined, and if the beginning of the
current string matches a rule, the related context is used. The start
point in the text is moved to the final point at which that rule
matched and a new loop of the rules begins, starting in the context
set by the matched rule.</para>

</sect3>

<sect3 id="highlight-system-rules">
<title>Rules</title>

<para>The detection rules are the heart of the highlighting detection
system. A rule is a string, character or <link
linkend="regular-expressions">regular expression</link> against which
to match the text being analyzed. It contains information about which
style to use for the matching part of the text. It may switch the
working context of the system either to an explicitly mentioned
context or to the previous context used by the text.</para>

<para>Rules are organized in context groups. A context group is used
for main text concepts within the format, for example quoted text
strings or comment blocks in program source code. This ensures that
the highlighting system does not need to loop through all rules when
it is not necessary, and that some character sequences in the text can
be treated differently depending on the current context.
</para>

<para>Contexts may be generated dynamically to allow the usage of instance
specific data in rules.</para>

</sect3>

<sect3 id="highlight-context-styles-keywords">
<title>Context Styles and Keywords</title>

<para>In some programming languages, integer numbers are treated
differently from floating point ones by the compiler (the program that
converts the source code to a binary executable), and there may be
characters having a special meaning within a quoted string. In such
cases, it makes sense to render them differently from the surroundings
so that they are easy to identify while reading the text. So even if
they do not represent special contexts, they may be seen as such by
the syntax highlighting system, so that they can be marked for
different rendering.</para>

<para>A syntax definition may contain as many styles as required to
cover the concepts of the format it is used for.</para>

<para>In many formats, there are lists of words that represent a
specific concept. For example, in programming languages, control
statements are one concept, data type names another, and built in
functions of the language a third. The &kappname; Syntax Highlighting
System can use such lists to detect and mark words in the text to
emphasize concepts of the text formats.</para>

</sect3>

<sect3 id="kate-highlight-system-default-styles">
<title>Default Styles</title>

<para>If you open a C++ source file, a &Java; source file and an
181
&HTML; document in &kappname;, you will see that even
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
though the formats are different, and thus different words are chosen
for special treatment, the colors used are the same. This is because
&kappname; has a predefined list of Default Styles which are employed by
the individual syntax definitions.</para>

<para>This makes it easy to recognize similar concepts in different
text formats. For example, comments are present in almost any
programming, scripting or markup language, and when they are rendered
using the same style in all languages, you do not have to stop and
think to identify them within the text.</para>

<tip>
<para>All styles in a syntax definition use one of the default
styles. A few syntax definitions use more styles than there are
defaults, so if you use a format often, it may be worth launching the
configuration dialog to see if some concepts use the same
style. For example, there is only one default style for strings, but as
the Perl programming language operates with two types of strings, you
can enhance the highlighting by configuring those to be slightly
different. All <link linkend="kate-highlight-default-styles">available default styles</link>
will be explained later.</para>
</tip>

</sect3>

</sect2>

<sect2 id="katehighlight-xml-format">
<title>The Highlight Definition &XML; Format</title>

<sect3>
<title>Overview</title>

215
<para>&kappname; uses the Syntax-Highlighting framework from &kde-frameworks;.
216
The default highlighting &XML; files shipped with &kappname; are compiled
217
218
219
into the Syntax-Highlighting library by default.
</para>

220
221
222
223
224
<para>This section is an overview of the Highlight Definition &XML;
format. Based on a small example it will describe the main components
and their meaning and usage. The next section will go into detail with
the highlight detection rules.</para>

225
226
227
228
229
230
231
<para>The formal definition, also known as the <acronym>XSD</acronym> you
find in <ulink url="https://commits.kde.org/syntax-highlighting?path=data/schema">Syntax
Highlighting repository</ulink> in the file <filename>language.xsd</filename>
</para>

<para>Custom <filename class="extension">.xml</filename> highlight definition files are
located in <filename class="directory">org.kde.syntax-highlighting/syntax/</filename> in
232
233
234
235
your user folder found with <userinput><command>qtpaths</command><option> --paths
GenericDataLocation</option></userinput> which usually are
<filename class="directory"><envar>$HOME</envar>/.local/share/</filename>
and <filename class="directory">/usr/share/</filename>.
236
237
</para>

238
239
240
241
<para>In Flatpak and Snap packages, the above directory will not work
as the data location is different for each application.
In a Flatpak application, the location of custom &XML; files is usually
<filename class="directory"><envar>$HOME</envar>/.var/app/<replaceable>flatpak-package-name</replaceable>/data/org.kde.syntax-highlighting/syntax/</filename>
242
and in a Snap application that location is
243
<filename class="directory"><envar>$HOME</envar>/snap/<replaceable>snap-package-name</replaceable>/current/.local/share/org.kde.syntax-highlighting/syntax/</filename>.
244
245
</para>

246
247
248
<para>On &Windows; these files are located <filename>%USERPROFILE%&#92;AppData&#92;Local&#92;org.kde.syntax-highlighting&#92;syntax</filename>.
<replaceable>%USERPROFILE%</replaceable> usually expands to <filename>C:&#92;Users&#92;<replaceable>user</replaceable></filename>.</para>

249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<para>In summary, for most configurations the directory of custom &XML;
files is as follows:</para>

<informaltable>
<tgroup cols="2">
<tbody>
<row>
<entry>For local user</entry>
<entry><filename class="directory"><envar>$HOME</envar>/.local/share/org.kde.syntax-highlighting/syntax/</filename></entry>
</row>
<row>
<entry>For all users</entry>
<entry><filename class="directory">/usr/share/org.kde.syntax-highlighting/syntax/</filename></entry>
</row>
<row>
<entry>For Flatpak packages</entry>
<entry><filename class="directory"><envar>$HOME</envar>/.var/app/<replaceable>flatpak-package-name</replaceable>/data/org.kde.syntax-highlighting/syntax/</filename></entry>
</row>
<row>
<entry>For Snap packages</entry>
<entry><filename class="directory"><envar>$HOME</envar>/snap/<replaceable>snap-package-name</replaceable>/current/.local/share/org.kde.syntax-highlighting/syntax/</filename></entry>
</row>
<row>
<entry>On &Windows;</entry>
<entry><filename>%USERPROFILE%&#92;AppData&#92;Local&#92;org.kde.syntax-highlighting&#92;syntax</filename></entry>
</row>
</tbody>
</tgroup>
</informaltable>

279
280
<para>If multiple files exist for the same language, the file with the highest <userinput>version</userinput> attribute in the <userinput>language</userinput> element will be loaded.</para>

281
282
283
284
<variablelist>
<title>Main sections of &kappname; Highlight Definition files</title>

<varlistentry>
285
<term>A highlighting file contains a header that sets the &XML; version:</term>
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
<listitem>
<programlisting>
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
</programlisting>
</listitem>
</varlistentry>

<varlistentry>
<term>The root of the definition file is the element <userinput>language</userinput>.
Available attributes are:</term>

<listitem>
<para>Required attributes:</para>
<para><userinput>name</userinput> sets the name of the language. It appears in the menus and dialogs afterwards.</para>
<para><userinput>section</userinput> specifies the category.</para>
<para><userinput>extensions</userinput> defines file extensions, such as &quot;*.cpp;*.h&quot;</para>
302
303
<para><userinput>version</userinput> specifies the current revision of the definition file in terms of an integer number. Whenever you change a highlighting definition file, make sure to increase this number.</para>
<para><userinput>kateversion</userinput> specifies the latest supported &kappname; version.</para>
304
305
306
307
308
309

<para>Optional attributes:</para>
<para><userinput>mimetype</userinput> associates files &MIME; type.</para>
<para><userinput>casesensitive</userinput> defines, whether the keywords are case sensitive or not.</para>
<para><userinput>priority</userinput> is necessary if another highlight definition file uses the same extensions. The higher priority will win.</para>
<para><userinput>author</userinput> contains the name of the author and his email-address.</para>
310
<para><userinput>license</userinput> contains the license, usually the MIT license for new syntax-highlighting files.</para>
311
<para><userinput>style</userinput> contains the provided language and is used by the indenters for the attribute <literal>required-syntax-style</literal>.</para>
312
<para><userinput>indenter</userinput> defines which indenter will be used by default. Available indenters are: <emphasis>ada, normal, cstyle, cmake, haskell, latex, lilypond, lisp, lua, pascal, python, replicode, ruby</emphasis> and <emphasis>xml</emphasis>.</para>
313
314
315
<para><userinput>hidden</userinput> defines whether the name should appear in &kappname;'s menus.</para>
<para>So the next line may look like this:</para>
<programlisting>
316
&lt;language name=&quot;C++&quot; version=&quot;1&quot; kateversion=&quot;2.4&quot; section=&quot;Sources&quot; extensions=&quot;*.cpp;*.h&quot; /&gt;
317
318
319
320
321
322
323
324
325
326
327
328
329
</programlisting>
</listitem>
</varlistentry>


<varlistentry>
<term>Next comes the <userinput>highlighting</userinput> element, which
contains the optional element <userinput>list</userinput> and the required
elements <userinput>contexts</userinput> and <userinput>itemDatas</userinput>.</term>
<listitem>
<para><userinput>list</userinput> elements contain a list of keywords. In
this case the keywords are <emphasis>class</emphasis> and <emphasis>const</emphasis>.
You can add as many lists as you need.</para>
330
331
332
333
334
335
336
337
338
<para>Since &kde-frameworks; 5.53, a list can include keywords from another
list or language/file, using the <userinput>include</userinput> element.
<userinput>##</userinput> is used to separate the list name and the language
definition name, in the same way as in the <userinput>IncludeRules</userinput> rule.
This is useful to avoid duplicating keyword lists, if you need to include the keywords
of another language/file. For example, the <emphasis>othername</emphasis> list
contains the <emphasis>str</emphasis> keyword and all the keywords of the
<emphasis>types</emphasis> list, which belongs to the <emphasis>ISO C++</emphasis>
language.</para>
339
340
341
342
343
344
345
346
347
348
349
350
351
352
<para>The <userinput>contexts</userinput> element contains all contexts.
The first context is by default the start of the highlighting. There are
two rules in the context <emphasis>Normal Text</emphasis>, which match
the list of keywords with the name <emphasis>somename</emphasis> and a
rule that detects a quote and switches the context to <emphasis>string</emphasis>.
To learn more about rules read the next chapter.</para>
<para>The third part is the <userinput>itemDatas</userinput> element. It
contains all color and font styles needed by the contexts and rules.
In this example, the <userinput>itemData</userinput> <emphasis>Normal Text</emphasis>,
<emphasis>String</emphasis> and <emphasis>Keyword</emphasis> are used.
</para>
<programlisting>
  &lt;highlighting&gt;
    &lt;list name=&quot;somename&quot;&gt;
353
354
355
356
357
358
      &lt;item&gt;class&lt;/item&gt;
      &lt;item&gt;const&lt;/item&gt;
    &lt;/list&gt;
    &lt;list name=&quot;othername&quot;&gt;
      &lt;item&gt;str&lt;/item&gt;
      &lt;include&gt;types##ISO C++&lt;/include&gt;
359
360
361
362
    &lt;/list&gt;
    &lt;contexts&gt;
      &lt;context attribute=&quot;Normal Text&quot; lineEndContext=&quot;#pop&quot; name=&quot;Normal Text&quot; &gt;
        &lt;keyword attribute=&quot;Keyword&quot; context=&quot;#stay&quot; String=&quot;somename&quot; /&gt;
363
        &lt;keyword attribute=&quot;Keyword&quot; context=&quot;#stay&quot; String=&quot;othername&quot; /&gt;
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
        &lt;DetectChar attribute=&quot;String&quot; context=&quot;string&quot; char=&quot;&amp;quot;&quot; /&gt;
      &lt;/context&gt;
      &lt;context attribute=&quot;String&quot; lineEndContext=&quot;#stay&quot; name=&quot;string&quot; &gt;
        &lt;DetectChar attribute=&quot;String&quot; context=&quot;#pop&quot; char=&quot;&amp;quot;&quot; /&gt;
      &lt;/context&gt;
    &lt;/contexts&gt;
    &lt;itemDatas&gt;
      &lt;itemData name=&quot;Normal Text&quot; defStyleNum=&quot;dsNormal&quot; /&gt;
      &lt;itemData name=&quot;Keyword&quot; defStyleNum=&quot;dsKeyword&quot; /&gt;
      &lt;itemData name=&quot;String&quot; defStyleNum=&quot;dsString&quot; /&gt;
    &lt;/itemDatas&gt;
  &lt;/highlighting&gt;
</programlisting>
</listitem>
</varlistentry>

<varlistentry>
<term>The last part of a highlight definition is the optional
<userinput>general</userinput> section. It may contain information
383
384
about keywords, code folding, comments, indentation, empty lines and
spell checking.</term>
385
386
387
388
389
390
391
392
393
394

<listitem>
<para>The <userinput>comment</userinput> section defines with what
string a single line comment is introduced. You also can define a
multiline comment using <emphasis>multiLine</emphasis> with the
additional attribute <emphasis>end</emphasis>. This is used if the
user presses the corresponding shortcut for <emphasis>comment/uncomment</emphasis>.</para>
<para>The <userinput>keywords</userinput> section defines whether
keyword lists are case sensitive or not. Other attributes will be
explained later.</para>
395
396
397
<para>The other sections, <userinput>folding</userinput>,
<userinput>emptyLines</userinput> and <userinput>spellchecking</userinput>,
are usually not necessary and are explained later.</para>
398
399
400
401
<programlisting>
  &lt;general&gt;
    &lt;comments&gt;
      &lt;comment name="singleLine" start="#"/&gt;
402
      &lt;comment name="multiLine" start="###" end="###" region="CommentFolding"/&gt;
403
404
    &lt;/comments&gt;
    &lt;keywords casesensitive="1"/&gt;
405
406
407
408
409
410
411
412
413
    &lt;folding indentationsensitive="0"/&gt;
    &lt;emptyLines&gt;
      &lt;emptyLine regexpr="\s+"/&gt;
      &lt;emptyLine regexpr="\s*#.*"/&gt;
    &lt;/emptyLines&gt;
    &lt;spellchecking&gt;
      &lt;encoding char="&#225;" string="\&#39;a"/&gt;
      &lt;encoding char="&#224;" string="\&#96;a"/&gt;
    &lt;/spellchecking&gt;
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
  &lt;/general&gt;
&lt;/language&gt;
</programlisting>
</listitem>
</varlistentry>

</variablelist>


</sect3>

<sect3 id="kate-highlight-sections">
<title>The Sections in Detail</title>
<para>This part will describe all available attributes for contexts,
itemDatas, keywords, comments, code folding and indentation.</para>

<variablelist>
<varlistentry>
<term>The element <userinput>context</userinput> belongs in the group
<userinput>contexts</userinput>. A context itself defines context specific
rules such as what should happen if the highlight system reaches the end of a
line. Available attributes are:</term>


<listitem>
<para><userinput>name</userinput> states the context name. Rules will use this name
to specify the context to switch to if the rule matches.</para>
441

442
443
444
445
446
447
<para><userinput>lineEndContext</userinput> defines the context the highlight
system switches to if it reaches the end of a line. This may either be a name
of another context, <userinput>#stay</userinput> to not switch the context
(&eg;. do nothing) or <userinput>#pop</userinput> which will cause it to leave this
context. It is possible to use for example <userinput>#pop#pop#pop</userinput>
to pop three times, or even <userinput>#pop#pop!OtherContext</userinput> to pop
448
449
two times and switch to the context named <userinput>OtherContext</userinput>.
It is also possible to switch to a context that belongs to another language definition,
450
in the same way as in the <userinput>IncludeRules</userinput> rules, &eg;,
451
452
453
454
<userinput>SomeContext##JavaScript</userinput>. Note that it is not possible to use
this context switch in combination with <userinput>#pop</userinput>, for example,
<userinput>#pop!SomeContext##JavaScript</userinput> is not valid.
Context switches are also described in <xref linkend="kate-highlight-rules-detailled"/>.</para>
455
<para><userinput>lineEmptyContext</userinput> defines the context if an empty
456
457
458
459
460
461
line is encountered. The nomenclature of context switches is the same as
previously described in <emphasis>lineEndContext</emphasis>. Default: #stay.</para>
<para><userinput>fallthroughContext</userinput> specifies the next context to
switch to if no rule matches. The nomenclature of context switches is
the same as previously described in <emphasis>lineEndContext</emphasis>.
Default: #stay.</para>
462
<para><userinput>fallthrough</userinput> defines if the highlight system switches
463
464
to the context specified in <userinput>fallthroughContext</userinput> if no rule
matches. Note that since &kde; &frameworks; 5.62 this attribute is deprecated
465
in favor of <userinput>fallthroughContext</userinput>, since if the
466
467
468
<userinput>fallthroughContext</userinput> attribute is present it is implicitly
understood that the value of <userinput>fallthrough</userinput> is
<emphasis>true</emphasis>. Default: <emphasis>false</emphasis>.</para>
469
470
471
472
<para><userinput>noIndentationBasedFolding</userinput> disables indentation-based folding
in the context. If indentation-based folding is not activated, this attribute is useless.
This is defined in the element <emphasis>folding</emphasis> of the group <emphasis>general</emphasis>.
Default: <emphasis>false</emphasis>.</para>
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
</listitem>
</varlistentry>


<varlistentry>
<term>The element <userinput>itemData</userinput> is in the group
<userinput>itemDatas</userinput>. It defines the font style and colors.
So it is possible to define your own styles and colors. However, we
recommend you stick to the default styles if possible so that the user
will always see the same colors used in different languages. Though,
sometimes there is no other way and it is necessary to change color
and font attributes. The attributes name and defStyleNum are required,
the others are optional. Available attributes are:</term>

<listitem>
<para><userinput>name</userinput> sets the name of the itemData.
Contexts and rules will use this name in their attribute
<emphasis>attribute</emphasis> to reference an itemData.</para>
<para><userinput>defStyleNum</userinput> defines which default style to use.
Available default styles are explained in detail later.</para>
<para><userinput>color</userinput> defines a color. Valid formats are
'#rrggbb' or '#rgb'.</para>
<para><userinput>selColor</userinput> defines the selection color.</para>
<para><userinput>italic</userinput> if <emphasis>true</emphasis>, the text will be italic.</para>
<para><userinput>bold</userinput> if <emphasis>true</emphasis>, the text will be bold.</para>
<para><userinput>underline</userinput> if <emphasis>true</emphasis>, the text will be underlined.</para>
<para><userinput>strikeout</userinput> if <emphasis>true</emphasis>, the text will be struck out.</para>
<para><userinput>spellChecking</userinput> if <emphasis>true</emphasis>, the text will be spellchecked.</para>
</listitem>
</varlistentry>


<varlistentry>
<term>The element <userinput>keywords</userinput> in the group
<userinput>general</userinput> defines keyword properties. Available attributes are:</term>

<listitem>
<para><userinput>casesensitive</userinput> may be <emphasis>true</emphasis>
or <emphasis>false</emphasis>. If <emphasis>true</emphasis>, all keywords
are matched case sensitively.</para>
<para><userinput>weakDeliminator</userinput> is a list of characters that
do not act as word delimiters. For example, the dot <userinput>'.'</userinput>
is a word delimiter. Assume a keyword in a <userinput>list</userinput> contains
a dot, it will only match if you specify the dot as a weak delimiter.</para>
<para><userinput>additionalDeliminator</userinput> defines additional delimiters.</para>
<para><userinput>wordWrapDeliminator</userinput> defines characters after which a
line wrap may occur.</para>
<para>Default delimiters and word wrap delimiters are the characters
<userinput>.():!+,-&lt;=&gt;%&amp;*/;?[]^{|}~\</userinput>, space (<userinput>' '</userinput>)
and tabulator (<userinput>'\t'</userinput>).</para>
</listitem>
</varlistentry>


<varlistentry>
<term>The element <userinput>comment</userinput> in the group
<userinput>comments</userinput> defines comment properties which are used
530
531
532
for <menuchoice><guimenu>Tools</guimenu><guimenuitem>Comment</guimenuitem></menuchoice>,
<menuchoice><guimenu>Tools</guimenu><guimenuitem>Uncomment</guimenuitem></menuchoice> and
<menuchoice><guimenu>Tools</guimenu><guimenuitem>Toggle Comment</guimenuitem></menuchoice>.
533
534
535
536
537
538
Available attributes are:</term>

<listitem>
<para><userinput>name</userinput> is either <emphasis>singleLine</emphasis>
or <emphasis>multiLine</emphasis>. If you choose <emphasis>multiLine</emphasis>
the attributes <emphasis>end</emphasis> and <emphasis>region</emphasis> are
539
540
required. If you choose <emphasis>singleLine</emphasis> you can add the optional
attribute <emphasis>position</emphasis>.</para>
541
<para><userinput>start</userinput> defines the string used to start a comment.
542
543
In C++ this would be &quot;/*&quot; in multiline comments. This attribute is required
for types <emphasis>multiLine</emphasis> and <emphasis>singleLine</emphasis>.</para>
544
<para><userinput>end</userinput> defines the string used to close a comment.
545
546
In C++ this would be &quot;*/&quot;. This attribute is only available and is
required for comments of type <emphasis>multiLine</emphasis>.</para>
547
548
549
550
551
<para><userinput>region</userinput> should be the name of the foldable
multiline comment. Assume you have <emphasis>beginRegion="Comment"</emphasis>
... <emphasis>endRegion="Comment"</emphasis> in your rules, you should use
<emphasis>region="Comment"</emphasis>. This way uncomment works even if you
do not select all the text of the multiline comment. The cursor only must be
552
553
554
555
in the multiline comment. This attribute is only available for type
<emphasis>multiLine</emphasis>.</para>
<para><userinput>position</userinput> defines where the single line comment is inserted.
By default, the single line comment is placed at the beginning of the line at column 0,
556
557
558
but if you use <emphasis>position="afterwhitespace"</emphasis> the comment is
inserted after leading whitespaces right, before the first non-whitespace character.
This is useful for putting comments correctly in languages where indentation
559
560
561
is important, such as Python or YAML. This attribute is optional and the only
possible value is <emphasis>afterwhitespace</emphasis>.
This is only available for type <emphasis>singleLine</emphasis>.</para>
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
</listitem>
</varlistentry>


<varlistentry>
<term>The element <userinput>folding</userinput> in the group
<userinput>general</userinput> defines code folding properties.
Available attributes are:</term>

<listitem>
<para><userinput>indentationsensitive</userinput> if <emphasis>true</emphasis>, the code folding markers
will be added indentation based, as in the scripting language Python. Usually you
do not need to set it, as it defaults to <emphasis>false</emphasis>.</para>
</listitem>
</varlistentry>


579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
<varlistentry>
<term>The element <userinput>emptyLine</userinput> in the group <userinput>emptyLines</userinput>
defines which lines should be treated as empty lines. This allows modifying the behavior of the
<emphasis>lineEmptyContext</emphasis> attribute in the elements <userinput>context</userinput>.
Available attributes are:</term>

<listitem>
<para><userinput>regexpr</userinput> defines a regular expression that will be treated as an empty line.
By default, empty lines do not contain any characters, therefore, this adds additional empty lines,
for example, if you want lines with spaces to also be considered empty lines.
However, in most syntax definitions you do not need to set this attribute.</para>
</listitem>
</varlistentry>


<varlistentry>
<term>The element <userinput>encoding</userinput> in the group <userinput>spellchecking</userinput>
defines a character encoding for spell checking. Available attributes:</term>

<listitem>
<para><userinput>char</userinput> is a encoded character.</para>
<para><userinput>string</userinput> is a sequence of characters that will be encoded as
the character <emphasis>char</emphasis> in the spell checking.
For example, in the language LaTeX, the string <userinput>\&quot;{A}</userinput> represents
the character <userinput>&#196;</userinput>.</para>
</listitem>
</varlistentry>


608
609
610
611
612
613
614
615
616
617
618
</variablelist>


</sect3>

<sect3 id="kate-highlight-default-styles">
<title>Available Default Styles</title>
<para>Default Styles were <link linkend="kate-highlight-system-default-styles">already explained</link>,
as a short summary: Default styles are predefined font and color styles.</para>
<variablelist>
<varlistentry>
Philipp A.'s avatar
Philipp A. committed
619
<term>General default styles:</term>
620
<listitem>
Yuri Chornoivan's avatar
Yuri Chornoivan committed
621
<para><userinput>dsNormal</userinput>, when no special highlighting is required.</para>
Philipp A.'s avatar
Philipp A. committed
622
623
<para><userinput>dsKeyword</userinput>, built-in language keywords.</para>
<para><userinput>dsFunction</userinput>, function calls and definitions.</para>
624
<para><userinput>dsVariable</userinput>, if applicable: variable names (&eg; $someVar in PHP/Perl).</para>
Philipp A.'s avatar
Philipp A. committed
625
626
627
<para><userinput>dsControlFlow</userinput>, control flow keywords like if, else, switch, break, return, yield, ...</para>
<para><userinput>dsOperator</userinput>, operators like + - * / :: &lt; &gt;</para>
<para><userinput>dsBuiltIn</userinput>, built-in functions, classes, and objects.</para>
628
<para><userinput>dsExtension</userinput>, common extensions, such as &Qt; classes and functions/macros in C++ and Python.</para>
Philipp A.'s avatar
Philipp A. committed
629
630
631
632
633
634
635
636
637
638
639
640
<para><userinput>dsPreprocessor</userinput>, preprocessor statements or macro definitions.</para>
<para><userinput>dsAttribute</userinput>, annotations such as @override and __declspec(...).</para>
</listitem>
</varlistentry>

<varlistentry>
<term>String-related default styles:</term>
<listitem>
<para><userinput>dsChar</userinput>, single characters, such as 'x'.</para>
<para><userinput>dsSpecialChar</userinput>, chars with special meaning in strings such as escapes, substitutions, or regex operators.</para>
<para><userinput>dsString</userinput>, strings like "hello world".</para>
<para><userinput>dsVerbatimString</userinput>, verbatim or raw strings like 'raw \backlash' in Perl, CoffeeScript, and shells, as well as r'\raw' in Python.</para>
641
<para><userinput>dsSpecialString</userinput>, SQL, regexes, HERE docs, &latex; math mode, ...</para>
Philipp A.'s avatar
Philipp A. committed
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
<para><userinput>dsImport</userinput>, import, include, require of modules.</para>
</listitem>
</varlistentry>

<varlistentry>
<term>Number-related default styles:</term>
<listitem>
<para><userinput>dsDataType</userinput>, built-in data types like int, void, u64.</para>
<para><userinput>dsDecVal</userinput>, decimal values.</para>
<para><userinput>dsBaseN</userinput>, values with a base other than 10.</para>
<para><userinput>dsFloat</userinput>, floating point values.</para>
<para><userinput>dsConstant</userinput>, built-in and user defined constants like PI.</para>
</listitem>
</varlistentry>

<varlistentry>
<term>Comment and documentation-related default styles:</term>
<listitem>
<para><userinput>dsComment</userinput>, comments.</para>
<para><userinput>dsDocumentation</userinput>, /** Documentation comments */ or """docstrings""".</para>
<para><userinput>dsAnnotation</userinput>, documentation commands like @param, @brief.</para>
<para><userinput>dsCommentVar</userinput>, the variable names used in above commands, like "foobar" in @param foobar.</para>
<para><userinput>dsRegionMarker</userinput>, region markers like //BEGIN, //END in comments.</para>
</listitem>
</varlistentry>

<varlistentry>
<term>Other default styles:</term>
<listitem>
<para><userinput>dsInformation</userinput>, notes and tips like @note in doxygen.</para>
<para><userinput>dsWarning</userinput>, warnings like @warning in doxygen.</para>
<para><userinput>dsAlert</userinput>, special words like TODO, FIXME, XXXX.</para>
<para><userinput>dsError</userinput>, error highlighting and wrong syntax.</para>
<para><userinput>dsOthers</userinput>, when nothing else fits.</para>
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
</listitem>
</varlistentry>
</variablelist>

</sect3>

</sect2>

<sect2 id="kate-highlight-rules-detailled">
<title>Highlight Detection Rules</title>

<para>This section describes the syntax detection rules.</para>

<para>Each rule can match zero or more characters at the beginning of
the string they are tested against. If the rule matches, the matching
characters are assigned the style or <emphasis>attribute</emphasis>
defined by the rule, and a rule may ask that the current context is
switched.</para>

<para>A rule looks like this:</para>

<programlisting>&lt;RuleName attribute=&quot;(identifier)&quot; context=&quot;(identifier)&quot; [rule specific attributes] /&gt;</programlisting>

<para>The <emphasis>attribute</emphasis> identifies the style to use
for matched characters by name, and the <emphasis>context</emphasis>
identifies the context to use from here.</para>

<para>The <emphasis>context</emphasis> can be identified by:</para>

<itemizedlist>
<listitem>
<para>An <emphasis>identifier</emphasis>, which is the name of the other
context.</para>
</listitem>
<listitem>
<para>An <emphasis>order</emphasis> telling the engine to stay in the
current context (<userinput>#stay</userinput>), or to pop back to a
previous context used in the string (<userinput>#pop</userinput>).</para>
<para>To go back more steps, the #pop keyword can be repeated:
<userinput>#pop#pop#pop</userinput></para>
</listitem>
<listitem>
<para>An <emphasis>order</emphasis> followed by an exclamation mark
(<emphasis>!</emphasis>) and an <emphasis>identifier</emphasis>, which
will make the engine first follow the order and then switch to the
721
other context, &eg; <userinput>#pop#pop!OtherContext</userinput>.</para>
722
</listitem>
723
724
725
726
727
728
729
730
731
732
733
<listitem>
<para>An <emphasis>identifier</emphasis>, which is a context name,
followed by two hashes (<userinput>##</userinput>) and another
<emphasis>identifier</emphasis>, which is the name of a language definition.
This naming is similar to that used in <userinput>IncludeRules</userinput>
rules and allows you to switch to a context belonging to another syntax
highlighting definition, e.g. <userinput>SomeContext##JavaScript</userinput>.
Note that it is not possible to use this context switch in combination with
<userinput>#pop</userinput>, for example,
<userinput>#pop!SomeContext##JavaScript</userinput> is not valid.</para>
</listitem>
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
</itemizedlist>

<para>Rule specific attributes varies and are described in the
following sections.</para>

<itemizedlist>
<title>Common attributes</title>
<para>All rules have the following attributes in common and are
available whenever <userinput>(common attributes)</userinput> appears.
<emphasis>attribute</emphasis> and <emphasis>context</emphasis>
are required attributes, all others are optional.
</para>

<listitem>
<para><emphasis>attribute</emphasis>: An attribute maps to a defined <emphasis>itemData</emphasis>.</para>
</listitem>
<listitem>
<para><emphasis>context</emphasis>: Specify the context to which the highlighting system switches if the rule matches.</para>
</listitem>
<listitem>
<para><emphasis>beginRegion</emphasis>: Start a code folding block. Default: unset.</para>
</listitem>
<listitem>
<para><emphasis>endRegion</emphasis>: Close a code folding block. Default: unset.</para>
</listitem>
<listitem>
<para><emphasis>lookAhead</emphasis>: If <emphasis>true</emphasis>, the
highlighting system will not process the matches length.
Default: <emphasis>false</emphasis>.</para>
</listitem>
<listitem>
<para><emphasis>firstNonSpace</emphasis>: Match only, if the string is
the first non-whitespace in the line. Default: <emphasis>false</emphasis>.</para>
</listitem>
<listitem>
<para><emphasis>column</emphasis>: Match only, if the column matches. Default: unset.</para>
</listitem>
</itemizedlist>

<itemizedlist>
<title>Dynamic rules</title>
<para>Some rules allow the optional attribute <userinput>dynamic</userinput>
of type boolean that defaults to <emphasis>false</emphasis>. If dynamic is
<emphasis>true</emphasis>, a rule can use placeholders representing the text
matched by a <emphasis>regular expression</emphasis> rule that switched to the
current context in its <userinput>string</userinput> or
<userinput>char</userinput> attributes. In a <userinput>string</userinput>,
the placeholder <replaceable>%N</replaceable> (where N is a number) will be
replaced with the corresponding capture <replaceable>N</replaceable>
783
from the calling regular expression, starting from 1. In a
784
785
786
787
788
789
790
791
792
793
794
<userinput>char</userinput> the placeholder must be a number
<replaceable>N</replaceable> and it will be replaced with the first character of
the corresponding capture <replaceable>N</replaceable> from the calling regular
expression. Whenever a rule allows this attribute it will contain a
<emphasis>(dynamic)</emphasis>.</para>

<listitem>
<para><emphasis>dynamic</emphasis>: may be <emphasis>(true|false)</emphasis>.</para>
</listitem>
</itemizedlist>

795
<para><userinput>How does it work:</userinput></para>
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814

<para>In the <link linkend="regular-expressions">regular expressions</link> of the
<userinput>RegExpr</userinput> rules, all text within simple curved brackets
<userinput>(PATTERN)</userinput> is captured and remembered.
These captures can be used in the context to which it is switched, in the rules with the
attribute <userinput>dynamic</userinput> <emphasis>true</emphasis>, by
<replaceable>%N</replaceable> (in <emphasis>String</emphasis>) or
<replaceable>N</replaceable> (in <emphasis>char</emphasis>).</para>

<para>It is important to mention that a text captured in a <userinput>RegExpr</userinput> rule is
only stored for the switched context, specified in its <userinput>context</userinput> attribute.</para>

<tip>
<itemizedlist>

<listitem>
<para>If the captures will not be used, both by dynamic rules and in the same regular expression,
<userinput>non-capturing groups</userinput> should be used: <userinput>(?:PATTERN)</userinput></para>
<para>The <emphasis>lookahead</emphasis> or <emphasis>lookbehind</emphasis> groups such as
815
816
<userinput>(?=PATTERN)</userinput>, <userinput>(?!PATTERN)</userinput> or
<userinput>(?&lt;=PATTERN)</userinput> are not captured.
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
See <link linkend="regular-expressions">Regular Expressions</link> for more information.</para>
</listitem>

<listitem>
<para>The capture groups can be used within the same regular expression,
using <replaceable>\N</replaceable> instead of <replaceable>%N</replaceable> respectively.
For more information, see <link linkend="regex-capturing">Capturing matching text (back references)</link>
in <link linkend="regular-expressions">Regular Expressions</link>.</para>
</listitem>

</itemizedlist>
</tip>

<para>Example 1:</para>
<para>In this simple example, the text matched by the regular expression
<userinput>=*</userinput> is captured and inserted into <replaceable>%1</replaceable>
in the dynamic rule. This allows the comment to end with the same amount of
<userinput>=</userinput> as at the beginning. This matches text like:
<userinput>[[ comment ]]</userinput>, <userinput>[=[ comment ]=]</userinput> or
<userinput>[=====[ comment ]=====]</userinput>.</para>
<para>In addition, the captures are available only in the switched context
<emphasis>Multi-line Comment</emphasis>.</para>

<programlisting>
&lt;context name="Normal" attribute="Normal Text" lineEndContext="#stay"&gt;
  &lt;RegExpr context="Multi-line Comment" attribute="Comment" String="\[(=*)\[" beginRegion="RegionComment"/&gt;
&lt;/context&gt;
&lt;context name="Multi-line Comment" attribute="Comment" lineEndContext="#stay"&gt;
  &lt;StringDetect context="#pop" attribute="Comment" String="]%1]" dynamic="true" endRegion="RegionComment"/&gt;
&lt;/context&gt;
</programlisting>

<para>Example 2:</para>
<para>In the dynamic rule, <replaceable>%1</replaceable> corresponds to the capture that matches
<userinput>#+</userinput>, and <replaceable>%2</replaceable> to <userinput>&amp;quot;+</userinput>.
This matches text as: <userinput>#label""""inside the context""""#</userinput>.</para>
<para>These captures will not be available in other contexts, such as
<emphasis>OtherContext</emphasis>, <emphasis>FindEscapes</emphasis> or
<emphasis>SomeContext</emphasis>.</para>

<programlisting>
&lt;context name="SomeContext" attribute="Normal Text" lineEndContext="#stay"&gt;
  &lt;RegExpr context="#pop!NamedString" attribute="String" String="(#+)(?:[\w-]|[^[:ascii:]])(&amp;quot;+)"/&gt;
&lt;/context&gt;
&lt;context name="NamedString" attribute="String" lineEndContext="#stay"&gt;
  &lt;RegExpr context="#pop!OtherContext" attribute="String" String="%2(?:%1)?" dynamic="true"/&gt;
  &lt;DetectChar context="FindEscapes" attribute="Escape" char="\"/&gt;
&lt;/context&gt;
</programlisting>

<para>Example 3:</para>
<para>This matches text like:
<userinput>Class::function&lt;T&gt;( ... )</userinput>.</para>

<programlisting>
&lt;context name="Normal" attribute="Normal Text" lineEndContext="#stay"&gt;
873
874
  &lt;RegExpr context="FunctionName" lookAhead="true"
              String="\b([a-zA-Z_][\w-]*)(::)([a-zA-Z_][\w-]*)(?:&amp;lt;[\w\-\s]*&amp;gt;)?(\()"/&gt;
875
876
877
878
879
880
881
882
883
&lt;/context&gt;
&lt;context name="FunctionName" attribute="Normal Text" lineEndContext="#pop"&gt;
  &lt;StringDetect context="#stay" attribute="Class" String="%1" dynamic="true"/&gt;
  &lt;StringDetect context="#stay" attribute="Operator" String="%2" dynamic="true"/&gt;
  &lt;StringDetect context="#stay" attribute="Function" String="%3" dynamic="true"/&gt;
  &lt;DetectChar context="#pop" attribute="Normal Text" char="4" dynamic="true"/&gt;
&lt;/context&gt;
</programlisting>

884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
<itemizedlist>
<title>Local deliminators</title>
<para>Some rules allow the optional attributes <userinput>weakDeliminator</userinput>
and <userinput>additionalDeliminator</userinput> which are combined with attributes
of the same name of <userinput>keywords</userinput> tag. For example, when
<userinput>'%'</userinput> is a weak delimiter of <userinput>keywords</userinput>,
it can become a word delimiter only for a rule by putting it in its
<userinput>additionalDeliminator</userinput> attribute. Whenever a rule allows these
attributes it will contain a <emphasis>(local deliminators)</emphasis>.</para>

<listitem>
<para><emphasis>weakDeliminator</emphasis>: list of characters that do not act as word
delimiters.</para>
</listitem>
<listitem>
<para><emphasis>additionalDeliminator</emphasis>: defines additional delimiters.</para>
</listitem>
</itemizedlist>

903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
<sect3 id="highlighting-rules-in-detail">
<title>The Rules in Detail</title>

<variablelist>
<varlistentry>
<term>DetectChar</term>
<listitem>
<para>Detect a single specific character. Commonly used for example to
find the ends of quoted strings.</para>
<programlisting>&lt;DetectChar char=&quot;(character)&quot; (common attributes) (dynamic) /&gt;</programlisting>
<para>The <userinput>char</userinput> attribute defines the character
to match.</para>
</listitem>
</varlistentry>

<varlistentry>
<term>Detect2Chars</term>
<listitem>
<para>Detect two specific characters in a defined order.</para>
922
<programlisting>&lt;Detect2Chars char=&quot;(character)&quot; char1=&quot;(character)&quot; (common attributes) /&gt;</programlisting>
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
<para>The <userinput>char</userinput> attribute defines the first character to match,
<userinput>char1</userinput> the second.</para>
</listitem>
</varlistentry>

<varlistentry>
<term>AnyChar</term>
<listitem>
<para>Detect one character of a set of specified characters.</para>
<programlisting>&lt;AnyChar String=&quot;(string)&quot; (common attributes) /&gt;</programlisting>
<para>The <userinput>String</userinput> attribute defines the set of
characters.</para>
</listitem>
</varlistentry>

<varlistentry>
<term>StringDetect</term>
<listitem>
<para>Detect an exact string.</para>
<programlisting>&lt;StringDetect String=&quot;(string)&quot; [insensitive=&quot;true|false&quot;] (common attributes) (dynamic) /&gt;</programlisting>
<para>The <userinput>String</userinput> attribute defines the string
to match. The <userinput>insensitive</userinput> attribute defaults to
<emphasis>false</emphasis> and is passed to the string comparison
function. If the value is <emphasis>true</emphasis> insensitive
comparing is used.</para>
</listitem>
</varlistentry>

<varlistentry>
<term>WordDetect</term>
<listitem>
<para>Detect an exact string but additionally require word boundaries
such as a dot <userinput>'.'</userinput> or a whitespace on the beginning
and the end of the word. Think of <userinput>\b&lt;string&gt;\b</userinput>
in terms of a regular expression, but it is faster than the rule <userinput>RegExpr</userinput>.</para>
958
<programlisting>&lt;WordDetect String=&quot;(string)&quot; [insensitive=&quot;true|false&quot;] (common attributes) (local deliminators) /&gt;</programlisting>
959
960
961
962
963
<para>The <userinput>String</userinput> attribute defines the string
to match. The <userinput>insensitive</userinput> attribute defaults to
<emphasis>false</emphasis> and is passed to the string comparison
function. If the value is <emphasis>true</emphasis> insensitive
comparing is used.</para>
964
<para>Since: &kate; 3.5 (&kde; 4.5)</para>
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
</listitem>
</varlistentry>

<varlistentry>
<term>RegExpr</term>
<listitem>
<para>Matches against a regular expression.</para>
<programlisting>&lt;RegExpr String=&quot;(string)&quot; [insensitive=&quot;true|false&quot;] [minimal=&quot;true|false&quot;] (common attributes) (dynamic) /&gt;</programlisting>
<para>The <userinput>String</userinput> attribute defines the regular
expression.</para>
<para><userinput>insensitive</userinput> defaults to
<emphasis>false</emphasis> and is passed to the regular expression
engine.</para>
<para><userinput>minimal</userinput> defaults to
<emphasis>false</emphasis> and is passed to the regular expression
engine.</para>
<para>Because the rules are always matched against the beginning of
the current string, a regular expression starting with a caret
(<literal>^</literal>) indicates that the rule should only be
matched against the start of a line.</para>
<para>See <link linkend="regular-expressions">Regular Expressions</link>
for more information on those.</para>
</listitem>
</varlistentry>

<varlistentry>
<term>keyword</term>
<listitem>
<para>Detect a keyword from a specified list.</para>
994
<programlisting>&lt;keyword String=&quot;(list name)&quot; (common attributes) (local deliminators) /&gt;</programlisting>
995
996
997
998
999
1000
1001
1002
1003
1004
<para>The <userinput>String</userinput> attribute identifies the
keyword list by name. A list with that name must exist.</para>
<para>The highlighting system processes keyword rules in a very optimized way.
This makes it an absolute necessity that any keywords to be matched need to be
surrounded by defined delimiters, either implied (the default delimiters),
or explicitly specified within the <emphasis>additionalDeliminator</emphasis>
property of the <emphasis>keywords</emphasis> tag.</para>
<para>If a keyword to be matched shall contain a delimiter character, this
respective character must be added to the <emphasis>weakDeliminator</emphasis>
property of the <emphasis>keywords</emphasis> tag.  This character will then
1005
1006
1007
1008
loose its delimiter property in all <emphasis>keyword</emphasis> rules. It is
also possible to use the <emphasis>weakDeliminator</emphasis> attribute of
<emphasis>keyword</emphasis> so that this modification only applies to this
rule.</para>
1009
1010
1011
1012
1013
1014
</listitem>
</varlistentry>

<varlistentry>
<term>Int</term>
<listitem>
1015
<para>Detect an integer number (as the regular expression: <userinput>\b[0-9]+</userinput>).</para>
1016
<para><programlisting>&lt;Int (common attributes) (local deliminators) /&gt;</programlisting></para>
1017
<para>This rule has no specific attributes.</para>
1018
1019
1020
1021
1022
1023
</listitem>
</varlistentry>

<varlistentry>
<term>Float</term>
<listitem>
1024
1025
<para>Detect a floating point number (as the regular expression:
<userinput>(\b[0-9]+\.[0-9]*|\.[0-9]+)([eE][-+]?[0-9]+)?</userinput>).</para>
1026
<para><programlisting>&lt;Float (common attributes) (local deliminators) /&gt;</programlisting></para>
1027
<para>This rule has no specific attributes.</para>
1028
1029
1030
1031
1032
1033
</listitem>
</varlistentry>

<varlistentry>
<term>HlCOct</term>
<listitem>
1034
1035
<para>Detect an octal point number representation (as the regular
expression: <userinput>\b0[0-7]+</userinput>).</para>
1036
<para><programlisting>&lt;HlCOct (common attributes) (local deliminators) /&gt;</programlisting></para>
1037
1038
1039
1040
1041
1042
1043
<para>This rule has no specific attributes.</para>
</listitem>
</varlistentry>

<varlistentry>
<term>HlCHex</term>
<listitem>
1044
1045
<para>Detect a hexadecimal number representation (as a regular expression:
<userinput>\b0[xX][0-9a-fA-F]+</userinput>).</para>
1046
<para><programlisting>&lt;HlCHex (common attributes) (local deliminators) /&gt;</programlisting></para>
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
<para>This rule has no specific attributes.</para>
</listitem>
</varlistentry>

<varlistentry>
<term>HlCStringChar</term>
<listitem>
<para>Detect an escaped character.</para>
<para><programlisting>&lt;HlCStringChar (common attributes) /&gt;</programlisting></para>
<para>This rule has no specific attributes.</para>

<para>It matches literal representations of characters commonly used in
program code, for example <userinput>\n</userinput>
(newline) or <userinput>\t</userinput> (TAB).</para>

<para>The following characters will match if they follow a backslash
(<literal>\</literal>):
<userinput>abefnrtv&quot;'?\</userinput>. Additionally, escaped
hexadecimal numbers such as for example <userinput>\xff</userinput> and
escaped octal numbers, for example <userinput>\033</userinput> will
match.</para>

</listitem>
</varlistentry>

<varlistentry>
<term>HlCChar</term>
<listitem>
<para>Detect an C character.</para>
<para><programlisting>&lt;HlCChar (common attributes) /&gt;</programlisting></para>
<para>This rule has no specific attributes.</para>

<para>It matches C characters enclosed in a tick (Example: <userinput>'c'</userinput>).
The ticks may be a simple character or an escaped character.
See HlCStringChar for matched escaped character sequences.</para>

</listitem>
</varlistentry>

<varlistentry>
<term>RangeDetect</term>
<listitem>
<para>Detect a string with defined start and end characters.</para>
<programlisting>&lt;RangeDetect char=&quot;(character)&quot;  char1=&quot;(character)&quot; (common attributes) /&gt;</programlisting>
<para><userinput>char</userinput> defines the character starting the range,
<userinput>char1</userinput> the character ending the range.</para>
<para>Useful to detect for example small quoted strings and the like, but
note that since the highlighting engine works on one line at a time, this
will not find strings spanning over a line break.</para>
</listitem>
</varlistentry>

<varlistentry>
<term>LineContinue</term>
<listitem>
<para>Matches a specified char at the end of a line.</para>
<programlisting>&lt;LineContinue (common attributes) [char="\"] /&gt;</programlisting>
<para><userinput>char</userinput> optional character to match, default is
1105
backslash (<userinput>'\'</userinput>). New since &kde; 4.13.</para>
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
<para>This rule is useful for switching context at end of line. This is needed for
 example in C/C++ to continue macros or strings.</para>
</listitem>
</varlistentry>

<varlistentry>
<term>IncludeRules</term>
<listitem>
<para>Include rules from another context or language/file.</para>
<programlisting>&lt;IncludeRules context=&quot;contextlink&quot; [includeAttrib=&quot;true|false&quot;] /&gt;</programlisting>

<para>The <userinput>context</userinput> attribute defines which context to include.</para>
<para>If it is a simple string it includes all defined rules into the current context, example:
<programlisting>&lt;IncludeRules context=&quot;anotherContext&quot; /&gt;</programlisting></para>

<para>
If the string contains a <userinput>##</userinput> the highlight system
will look for a context from another language definition with the given name,
for example
<programlisting>&lt;IncludeRules context=&quot;String##C++&quot; /&gt;</programlisting>
would include the context <emphasis>String</emphasis> from the <emphasis>C++</emphasis>
highlighting definition.</para>
<para>If <userinput>includeAttrib</userinput> attribute is
<emphasis>true</emphasis>, change the destination attribute to the one of
the source. This is required to make, for example, commenting work, if text
matched by the included context is a different highlight from the host
context.
</para>
</listitem>
</varlistentry>


<varlistentry>
<term>DetectSpaces</term>
<listitem>
<para>Detect whitespaces.</para>
<programlisting>&lt;DetectSpaces (common attributes) /&gt;</programlisting>

<para>This rule has no specific attributes.</para>
<para>Use this rule if you know that there can be several whitespaces ahead,
for example in the beginning of indented lines. This rule will skip all
whitespace at once, instead of testing multiple rules and skipping one at a
time due to no match.</para>
</listitem>
</varlistentry>


<varlistentry>
<term>DetectIdentifier</term>
<listitem>
1156
1157
<para>Detect identifier strings (as the regular expression:
<userinput>[a-zA-Z_][a-zA-Z0-9_]*</userinput>).</para>
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
<programlisting>&lt;DetectIdentifier (common attributes) /&gt;</programlisting>

<para>This rule has no specific attributes.</para>
<para>Use this rule to skip a string of word characters at once, rather than
testing with multiple rules and skipping one at a time due to no match.</para>
</listitem>
</varlistentry>

</variablelist>
</sect3>

<sect3>
<title>Tips &amp; Tricks</title>

<itemizedlist>
<para>Once you have understood how the context switching works it will be
easy to write highlight definitions. Though you should carefully check what
rule you choose in what situation. Regular expressions are very mighty, but
they are slow compared to the other rules. So you may consider the following
tips.
</para>

<listitem>
<para>If you only match two characters use <userinput>Detect2Chars</userinput>
instead of <userinput>StringDetect</userinput>. The same applies to
<userinput>DetectChar</userinput>.</para>
</listitem>
<listitem>
<para>Regular expressions are easy to use but often there is another much
faster way to achieve the same result. Consider you only want to match
the character <userinput>'#'</userinput> if it is the first character in the
line. A regular expression based solution would look like this:
<programlisting>&lt;RegExpr attribute=&quot;Macro&quot; context=&quot;macro&quot; String=&quot;^\s*#&quot; /&gt;</programlisting>
You can achieve the same much faster in using:
<programlisting>&lt;DetectChar attribute=&quot;Macro&quot; context=&quot;macro&quot; char=&quot;#&quot; firstNonSpace=&quot;true&quot; /&gt;</programlisting>
If you want to match the regular expression <userinput>'^#'</userinput> you
can still use <userinput>DetectChar</userinput> with the attribute <userinput>column=&quot;0&quot;</userinput>.
The attribute <userinput>column</userinput> counts characters, so a tabulator is only one character.
</para>
</listitem>
<listitem>
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
<para>In <userinput>RegExpr</userinput> rules, use the attribute <userinput>column="0"</userinput> if the pattern
<userinput>^PATTERN</userinput> will be used to match text at the beginning of a line.
This improves performance, as it will avoid looking for matches in the rest of the columns.</para>
</listitem>
<listitem>
<para>In regular expressions, use non-capturing groups <userinput>(?:PATTERN)</userinput> instead of
capturing groups <userinput>(PATTERN)</userinput>, if the captures will not be used in the same regular
expression or in dynamic rules. This avoids storing captures unnecessarily.</para>
</listitem>
<listitem>
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
<para>You can switch contexts without processing characters. Assume that you
want to switch context when you meet the string <userinput>*/</userinput>, but
need to process that string in the next context. The below rule will match, and
the <userinput>lookAhead</userinput> attribute will cause the highlighter to
keep the matched string for the next context.
<programlisting>&lt;Detect2Chars attribute=&quot;Comment&quot; context=&quot;#pop&quot; char=&quot;*&quot; char1=&quot;/&quot; lookAhead=&quot;true&quot; /&gt;</programlisting>
</para>
</listitem>
<listitem>
<para>Use <userinput>DetectSpaces</userinput> if you know that many whitespaces occur.</para>
</listitem>
<listitem>
<para>Use <userinput>DetectIdentifier</userinput> instead of the regular expression <userinput>'[a-zA-Z_]\w*'</userinput>.</para>
</listitem>
<listitem>
<para>Use default styles whenever you can. This way the user will find a familiar environment.</para>
</listitem>
<listitem>
1227
<para>Look into other &XML; files to see how other people implement tricky rules.</para>
1228
1229
</listitem>
<listitem>
1230
<para>You can validate every &XML; file by using the command
1231
1232
1233
1234
1235
<command>validatehl.sh language.xsd mySyntax.xml</command>.
The files <filename>validatehl.sh</filename> and <filename>language.xsd</filename>
are available in <ulink url="https://commits.kde.org/syntax-highlighting?path=data/schema">Syntax
Highlighting repository</ulink>.
</para>
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
</listitem>
<listitem>
<para>If you repeat complex regular expression very often you can use
<emphasis>ENTITIES</emphasis>. Example:</para>
<programlisting>
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE language SYSTEM "language.dtd"
[
        &lt;!ENTITY myref    "[A-Za-z_:][\w.:_-]*"&gt;
]&gt;
</programlisting>
<para>Now you can use <emphasis>&amp;myref;</emphasis> instead of the regular
expression.</para>
</listitem>
</itemizedlist>
</sect3>

</sect2>

</sect1>


1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
<sect1 id="color-themes">
<title>Working with Color Themes</title>

<sect2 id="color-themes-overview">

<title>Overview</title>

<para>Color themes define the colors of the
<link linkend="kate-part">text editing area</link> and the
<link linkend="highlight">syntax highlighting</link>. A color
theme encompasses the following:
<itemizedlist>
<listitem><para>The text style, used for syntax highlighting through the
<emphasis>default styles attributes</emphasis>. For example, the text
color and the selected text color.</para></listitem>
<listitem><para>The background of the text editing area, including the text
selection and the current line.</para></listitem>
<listitem><para>The icon border of the text area: their background, the separator line,
the line numbers, the line word wrap markers, the modified line marks and
the code folding.</para></listitem>
<listitem><para>Text decorators such as the search markers, the indentation and tab/space
line marks, the bracket matching and the spell checking.</para></listitem>
<listitem><para>Bookmarks and snippets.</para></listitem>
</itemizedlist>
</para>

<para>To avoid confusion, the following is out of scope:
<itemizedlist>
<listitem><para>The font type and the font size.</para></listitem>
<listitem><para>The colors of the text editing application, such as the scroll bar map, the menus,
the tab bar, the window color, etc. In &kde; applications, like &kate; or &kdevelop;, these colors
are defined by the <userinput>&kde; &plasma; global color scheme</userinput>, which are set in
the <ulink url="help:/kcontrol/colors/"><quote>Colors</quote> module in &systemsettings;</ulink>
or from the application itself in the menu
<menuchoice><guimenu>Settings</guimenu><guisubmenu>Color Scheme</guisubmenu></menuchoice>.
</para></listitem>
</itemizedlist>
</para>

<mediaobject>
1298
<imageobject><imagedata format="PNG" fileref="breeze-color-theme-preview.png"/></imageobject>
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
<textobject><phrase><quote>Breeze Light</quote> and <quote>Breeze Dark</quote> color themes
with the <quote>C++</quote> syntax highlighting.</phrase>
</textobject>
<caption><para><quote>Breeze Light</quote> and <quote>Breeze Dark</quote> color themes
with the <quote>C++</quote> syntax highlighting.</para>
</caption>
</mediaobject>

</sect2>

<sect2 id="color-themes-ksyntaxhighlighting">

<title>The KSyntaxHighlighting Color Themes</title>

<para>The <ulink url="https://api.kde.org/frameworks/syntax-highlighting/html/">KSyntaxHighlighting</ulink>
framework, which is the <link linkend="highlight">syntax highlighting</link> engine,
is the library that <userinput>provides and manages the color themes</userinput>.
This is part of &kde; &frameworks; and is used in &kde; text editors such as
<ulink url="https://apps.kde.org/en/kate">&kate;</ulink>,
<ulink url="https://apps.kde.org/en/kwrite">&kwrite;</ulink>,
<ulink url="https://apps.kde.org/en/kile">&kile;</ulink> and
<ulink url="https://apps.kde.org/en/kdevelop">&kdevelop;</ulink>.
This dependency looks like the following:</para>

<mediaobject>
1324
<imageobject><imagedata format="PNG" fileref="kf5-ksyntaxhighlighting.png"/></imageobject>
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
<textobject><phrase>Dependence of &kde; &frameworks; 5 libraries on text editors.</phrase></textobject>
<caption><para>Dependence of &kde; &frameworks; libraries on text editors.</para>
</caption>
</mediaobject>

<para>KSyntaxHighlighting includes a variety of built-in themes which are displayed on
the <ulink url="https://kate-editor.org/themes/"><quote>Color Themes</quote> page of
the Kate editor website</ulink>.</para>

<para>The <ulink url="https://api.kde.org/frameworks/ktexteditor/html/">KTextEditor</ulink>
framework, which is the text editing engine, provides a user interface for creating and editing
color themes, including a tool for importing and exporting themes. This is the simplest way to
create and edit them, you can access it from the
<link linkend="config-dialog"><quote>Configure</quote> dialog</link> of the text editor.
More details in <xref linkend="color-themes-gui"/>.</para>

<mediaobject>
1342
<imageobject><imagedata format="PNG" fileref="color-themes-gui-breeze-dark-default-text-styles.png"/></imageobject>
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
<textobject><phrase>The &GUI; to manage color themes in &kate;'s settings.</phrase></textobject>
<caption><para>The &GUI; to manage color themes in &kate;'s settings.</para>
</caption>
</mediaobject>

<para>It is important to mention that, in the &kde; text editors like &kate; or &kdevelop;,
the KSyntaxHighlighting color themes are used
<ulink url="https://kate-editor.org/post/2020/2020-09-13-kate-color-themes-5.75/">since
&kde; &frameworks; 5.75</ulink>, released on October 10, 2020. Previously, &kate;'s color
schemes (KConfig based schema config) were used and are now deprecated. However, it is
possible to convert the old &kate; schemes to the KSyntaxHighlighting color themes.
The <ulink url="https://invent.kde.org/frameworks/syntax-highlighting">KSyntaxHighlighting
repository</ulink> includes the <userinput>utils/kateschema_to_theme_converter.py</userinput>
script and the <userinput>utils/schema-converter/</userinput> utility for that purpose.
</para>

</sect2>

<sect2 id="color-themes-json">

<title>The Color Themes &JSON; Format</title>

<sect3 id="color-themes-json-overview">

<title>Overview</title>

<para>Color themes are stored in &JSON; format files, with the
<userinput>.theme</userinput> extension.</para>

<para>In the <ulink url="https://invent.kde.org/frameworks/syntax-highlighting">
KSyntaxHighlighting source code</ulink>, the &JSON; files of built-in themes
are located in the <userinput>data/themes/</userinput> directory.
Note that in text editors, the built-in themes are compiled into the
KSyntaxHighlighting library, therefore, the way to access them is through the
source code or by <link linkend="color-themes-gui-import-export">exporting them
from the &GUI; to manage themes of KTextEditor</link>.</para>

<para>It is also possible to easily add additional or custom themes, which are
loaded from the file system. User-customized theme files are located in the
<filename class="directory">org.kde.syntax-highlighting/themes/</filename>
directory in your user folder, which you can find with the command
<userinput><command>qtpaths</command><option> --paths GenericDataLocation</option></userinput>
and are commonly <filename class="directory"><envar>$HOME</envar>/.local/share/</filename>
and <filename class="directory">/usr/share/</filename>.
</para>

1389
<para>In Flatpak and Snap packages, the above directory will not work
1390
as the data location is different for each application.
1391
1392
1393
1394
In a Flatpak application, the location of custom theme files is usually
<filename class="directory"><envar>$HOME</envar>/.var/app/<replaceable>flatpak-package-name</replaceable>/data/org.kde.syntax-highlighting/themes/</filename>
and in a Snap application that location is
<filename class="directory"><envar>$HOME</envar>/snap/<replaceable>snap-package-name</replaceable>/current/.local/share/org.kde.syntax-highlighting/themes/</filename>.
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
</para>

<para>On &Windows; these files are located
<filename>%USERPROFILE%&#92;AppData&#92;Local&#92;org.kde.syntax-highlighting&#92;themes</filename>.
<replaceable>%USERPROFILE%</replaceable> usually expands to
<filename>C:&#92;Users&#92;<replaceable>user-name</replaceable></filename>.</para>

<para>In summary, for most configurations the custom themes directory is as follows:</para>

<informaltable>
<tgroup cols="2">
<tbody>
<row>
<entry>For local user</entry>
<entry><filename class="directory"><envar>$HOME</envar>/.local/share/org.kde.syntax-highlighting/themes/</filename></entry>
</row>
<row>
<entry>For all users</entry>
<entry><filename class="directory">/usr/share/org.kde.syntax-highlighting/themes/</filename></entry>
</row>
<row>
<entry>For Flatpak packages</entry>
<entry><filename class="directory"><envar>$HOME</envar>/.var/app/<replaceable>flatpak-package-name</replaceable>/data/org.kde.syntax-highlighting/themes/</filename></entry>
</row>
<row>
<entry>For Snap packages</entry>
<entry><filename class="directory"><envar>$HOME</envar>/snap/<replaceable>snap-package-name</replaceable>/current/.local/share/org.kde.syntax-highlighting/themes/</filename></entry>
</row>
<row>
<entry>On &Windows;</entry>
<entry><filename>%USERPROFILE%&#92;AppData&#92;Local&#92;org.kde.syntax-highlighting&#92;themes</filename></entry>
</row>
</tbody>
</tgroup>
</informaltable>

<para>If multiple theme files exist with the same name, the file with the highest <userinput>revision</userinput> will be loaded.
</para>

</sect3>

<sect3 id="color-themes-json-basic">

<title>The &JSON; Structure</title>

<para>The structure of a &JSON; file is explained on
<ulink url="https://www.json.org">their website</ulink>.
Basically, a &JSON; format file consists of:
<itemizedlist>
<listitem><para>Collections of key/value pairs, separated by commas and grouped in
<userinput>{ }</userinput> which we will call <quote>objects</quote>.</para></listitem>
<listitem><para>Ordered lists of values, separated by commas and grouped in
<userinput>[ ]</userinput> which we will call <quote>array</quote>.</para></listitem></itemizedlist>
</para>

<para>The nomenclature <quote>key</quote>, <quote>value</quote>, <quote>object</quote>
and <quote>array</quote> will be used in this article. If this is your first time working
with &JSON; files, understanding them is as simple as looking at the examples below.
</para>

</sect3>

<sect3 id="color-themes-json-root">

<title>Main Sections of the &JSON; Color Theme Files</title>

<para>The root object of the color theme &JSON; file contains the following
schema keys:</para>

<itemizedlist>
<listitem><para><userinput>metadata</userinput>: It is mandatory. The value
is an object with the theme's metadata, such as name, revision and license.</para>
<para>This is detailed in <xref linkend="color-themes-json-metadata"/>.</para>
</listitem>

<listitem><para><userinput>editor-colors</userinput>: It is mandatory. The
value is an object with the colors of the text editing area, such as the
background, the icon border and the text decoration.</para>
<para>This is detailed in <xref linkend="color-themes-editor-colors"/>.</para>
</listitem>

<listitem><para><userinput>text-styles</userinput>: It is mandatory. The value
is an object with the <emphasis>default text style</emphasis> attributes of
the syntax highlighting. Each attribute defines its <emphasis>text color</emphasis>,
its <emphasis>selected text color</emphasis>, or whether it <emphasis>bold</emphasis>
or <emphasis>italic</emphasis>, for example. The text styles can be referenced
from <link linkend="kate-highlight-default-styles">the attributes of the syntax
definition &XML; files</link>.</para>
<para>This is detailed in <xref linkend="color-themes-text-styles"/>.</para>
</listitem>

<listitem><para><userinput>custom-styles</userinput>: It is optional. Defines
text styles for the attributes of specific syntax highlighting definitions.
For example, in a highlighting definition such as <userinput>Python</userinput>
or <userinput>Markdown</userinput> you can specify a different text style that
overrides the default defined in <userinput>text-styles</userinput>.</para>
<para>This is detailed in <xref linkend="color-themes-custom-styles"/>.</para>
</listitem>
</itemizedlist>

<para>The &JSON; language does not support comments. However, you can use the
optional key <userinput>_comments</userinput> in the root object to write comments,
for example, if you are adapting an existing theme you can put the URL of the
original repository. The most practical way is to use an array of strings.
</para>

<para>Below is an example file for the <quote>Breeze Light</quote> theme.
You can notice that, to avoid the example being too large, the
<userinput>editor-colors</userinput> and <userinput>text-styles</userinput>
objects do not contain all the required keys. You can see the full archive of
<ulink url="https://invent.kde.org/frameworks/syntax-highlighting/-/blob/master/data/themes/breeze-light.theme">
the <quote>Breeze Light</quote> theme in the KSyntaxHighlighting repository</ulink>.
</para>

<programlisting>
{
    "_comments": [
        "This is a comment.",
        "If this theme is an adaptation of another, put the link to the original repository."
    ],
    "metadata": {
        "name" : "Breeze Light",
        "revision" : 5,
        "copyright": [
            "SPDX-FileCopyrightText: 2016 Volker Krause &lt;vkrause@kde.org&gt;",
            "SPDX-FileCopyrightText: 2016 Dominik Haumann &lt;dhaumann@kde.org&gt;"
        ],
        "license": "SPDX-License-Identifier: MIT"
    },
    "editor-colors": {
        "BackgroundColor" : "#ffffff",
        "CodeFolding" : "#94caef",
        "BracketMatching" : "#ffff00",
        "CurrentLine" : "#f8f7f6",
        "IconBorder" : "#f0f0f0",
        "IndentationLine" : "#d2d2d2",
        "LineNumbers" : "#a0a0a0",
        "CurrentLineNumber" : "#1e1e1e",
        <replaceable>The other editor color keys...</replaceable>

    },
    "text-styles": {
        "Normal" : {
            "text-color" : "#1f1c1b",
            "selected-text-color" : "#ffffff",
            "bold" : false,
            "italic" : false,
            "underline" : false,
            "strike-through" : false
        },
        "Keyword" : {
            "text-color" : "#1f1c1b",
            "selected-text-color" : "#ffffff",
            "bold" : true
        },
        "Function" : {
            "text-color" : "#644a9b",
            "selected-text-color" : "#452886"
        },
        "Variable" : {
            "text-color" : "#0057ae",
            "selected-text-color" : "#00316e"
        },
        <replaceable>The other text style keys...</replaceable>

    },
    "custom-styles": {
        "ISO C++": {
            "Data Type": {
                "bold": true,
                "selected-text-color": "#009183",
                "text-color": "#00b5cf"
            },
            "Keyword": {
                "text-color": "#6431b3"
            }
        },
        "YAML": {
            "Attribute": {
                "selected-text-color": "#00b5cf",
                "text-color": "#00b5cf"
            }
        }
    }
}
</programlisting>

</sect3>

<sect3 id="color-themes-json-metadata">

<title>Metadata</title>

<para>The &JSON; object of the <userinput>metadata</userinput> key contains
relevant information on the theme. This object has the following keys:

<itemizedlist>
<listitem><para><userinput>name</userinput>: It is a <emphasis>string</emphasis>
sets the name of the language. It appears in the menus and dialogs afterwards.
It is mandatory.</para></listitem>

<listitem><para><userinput>revision</userinput>: It is an
<emphasis>integer</emphasis> number that specifies the current revision of the
theme file. Whenever you update a color theme file, make sure to increase this
number. It is mandatory.</para></listitem>

<listitem><para><userinput>license</userinput>: It is a
<emphasis>string</emphasis> that defines the license of the theme, using the
identifier <userinput>SPDX-License-Identifier</userinput> from the standard
<ulink url="https://spdx.dev/">SPDX license communication format</ulink>.
It is optional.</para>
<para>You can see the full list of SPDX license identifiers
<ulink url="https://spdx.org/licenses/">here</ulink>.</para></listitem>

<listitem><para><userinput>copyright</userinput>: It is an <emphasis>array</emphasis>
of <emphasis>strings</emphasis> that specifies the authors of the theme, using
the identifier <userinput>SPDX-FileCopyrightText</userinput> from the standard
<ulink url="https://spdx.dev/">SPDX license communication format</ulink>.
It is optional.</para></listitem>
</itemizedlist>
</para>

<programlisting>
"metadata": {
    "name" : "Breeze Light",
    "revision" : 5,
    "copyright": [
        "SPDX-FileCopyrightText: 2016 Volker Krause &lt;vkrause@kde.org&gt;",
        "SPDX-FileCopyrightText: 2016 Dominik Haumann &lt;dhaumann@kde.org&gt;"
    ],
    "license": "SPDX-License-Identifier: MIT"
}
</programlisting>

</sect3>

</sect2>

<sect2 id="color-themes-editing">

<title>Colors in Detail</title>

<para>This section details all the available color attributes and available
color settings.</para>

<sect3 id="color-themes-editor-colors">

<title>Editor Colors</title>

<para>Corresponds to the colors of the <link linkend="kate-part">text editing area</link>.</para>

<para>In the <link linkend="color-themes-json">&JSON; theme file</link>, the respective key
<userinput>editor-colors</userinput> has as value an <emphasis>object</emphasis> where each
key references an attribute color of the text editor. Here, <userinput>all available keys
are mandatory</userinput>, their values are <userinput>strings</userinput> with hexadecimal
color codes, like <quote>#00B5CF</quote>.
</para>

<para>In <link linkend="color-themes-gui">the &GUI; to manage themes of KTextEditor</link>,
these attributes can be modified in the <userinput><guilabel>Colors</guilabel></userinput> tab.
</para>

<para>The available keys are the following; the keys used in the
<link linkend="color-themes-json">&JSON; file</link> are listed in <emphasis>bold</emphasis>,
the names used in the <link linkend="color-themes-gui">&GUI;</link> are shown in parentheses.
</para>

<variablelist>

<varlistentry id="variable-prefcolors-colors-text-background">
<term><guilabel>Editor Background Colors</guilabel></term>
<listitem>

<variablelist>

<varlistentry id="variable-pref-colors-normal-text">
<term><userinput>BackgroundColor</userinput> (<guilabel>Text Area</guilabel>)</term>
<listitem><para>This is the default background for the editor area, it will be
the dominant color on the editor area.</para>
<mediaobject>
1675
<imageobject><imagedata format="PNG" fileref="editor-colors-BackgroundColor.png"/></imageobject>
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
<caption><para></para></caption>
</mediaobject>
</listitem>
</varlistentry>

<varlistentry id="variable-pref-colors-selected-text">
<term><userinput>TextSelection</userinput> (<guilabel>Selected Text</guilabel>)</term>
<listitem><para>This is the background for selected text.
</para>
<mediaobject>
1686
<imageobject><imagedata format="PNG" fileref="editor-colors-TextSelection.png"/></imageobject>
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
<caption><para></para></caption>
</mediaobject>
</listitem>
</varlistentry>

<varlistentry id="variable-pref-colors-current-line">
<term><userinput>CurrentLine</userinput> (<guilabel>Current Line</guilabel>)</term>
<listitem><para>Set the color for the current line. Setting this a bit different
from the Normal text background helps to keep focus on the current line.
</para>
<mediaobject>
1698
<imageobject><imagedata format="PNG" fileref="editor-colors-CurrentLine.png"/></imageobject>
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
<caption><para></para></caption>
</mediaobject>
</listitem>
</varlistentry>

<varlistentry id="variable-pref-colors-search-highlight">
<term><userinput>SearchHighlight</userinput> (<guilabel>Search Highlight</guilabel>)</term>
<listitem><para>Set the color for the text that matches your last search.
</para>
<mediaobject>
1709
<imageobject><imagedata format="PNG" fileref="editor-colors-SearchHighlight.png"/></imageobject>
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
<caption><para></para></caption>
</mediaobject>
</listitem>
</varlistentry>

<varlistentry id="variable-pref-colors-replace-highlight">
<term><userinput>ReplaceHighlight</userinput> (<guilabel>Replace Highlight</guilabel>)</term>
<listitem><para>Set the color for the text that matches your last replace
operation.</para>
<mediaobject>
1720
<imageobject><imagedata format="PNG" fileref="editor-colors-ReplaceHighlight.png"/></imageobject>
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
<caption><para></para></caption>
</mediaobject>
</listitem>
</varlistentry>

</variablelist>
</listitem>
</varlistentry>

<varlistentry id="variable-prefcolors-colors-icon-border">
<term><guilabel>Icon Border</guilabel></term>
<listitem>
<variablelist>

<varlistentry>
<term><userinput>IconBorder</userinput> (<guilabel>Background Area</guilabel>)</term>
<listitem><para>This color is used for the marks, line numbers and folding
marker borders in the left side of the editor view when they are displayed.
</para></listitem>
</varlistentry>

<varlistentry>
<term><userinput>LineNumbers</userinput> (<guilabel>Line Numbers</guilabel>)</term>
<listitem><para>This color is used to draw the line numbers on the left side of
the view when displayed.</para></listitem>
</varlistentry>

<varlistentry>
<term><userinput>CurrentLineNumber</userinput> (<guilabel>Current Line Number</guilabel>)</term>
<listitem><para>This color is used to draw the line number of the current line,
on the left side of the view when displayed. Setting this a bit different from
<quote>LineNumbers</quote> helps to keep focus on the current line.
</para></listitem>
</varlistentry>

<varlistentry>
<term><userinput>Separator</userinput> (<guilabel>Separator</guilabel>)</term>
<listitem><para>This color is used to draw the vertical line that separates the
icon border from the background of the text area.</para>
<mediaobject>
1761
<imageobject><imagedata format="PNG" fileref="editor-colors-IconBorder.png"/></imageobject>
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
<caption><para></para></caption>
</mediaobject>
</listitem>
</varlistentry>

<varlistentry>
<term><userinput>WordWrapMarker</userinput> (<guilabel>Word Wrap Marker</guilabel>)</term>
<listitem><para>This color is used to draw a pattern to the left of dynamically
wrapped lines when those are aligned vertically, as well as for the static word
wrap marker.</para>
<mediaobject>
1773
<imageobject><imagedata format="PNG" fileref="editor-colors-WordWrapMarker.png"/></imageobject>
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
<caption><para></para></caption>
</mediaobject>
</listitem>
</varlistentry>

<varlistentry>
<term><userinput>CodeFolding</userinput> (<guilabel>Code Folding</guilabel>)</term>
<listitem><para>This color is used to highlight the section of code that would
be folded when you click on the code folding arrow to the left of a document.
For more information, see
<link linkend="advanced-editing-tools-code-folding">the code
folding documentation</link>.</para>
<mediaobject>
1787
<imageobject><imagedata format="PNG" fileref="editor-colors-CodeFolding.png"/></imageobject>
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
<caption><para></para></caption>
</mediaobject>
</listitem>
</varlistentry>

<varlistentry>
<term><userinput>ModifiedLines</userinput> (<guilabel>Modified Lines</guilabel>)</term>
<listitem><para>This color is used to highlight to the left of a document lines
that have been modified but not yet saved.  For more information, see
<xref linkend="kate-part-line-modification"/>.</para></listitem>
</varlistentry>

<varlistentry>
<term><userinput>SavedLines</userinput> (<guilabel>Saved Lines</guilabel>)</term>
<listitem><para>This color is used to highlight to the left of a document lines
that have been modified this session and saved.  For more information, see
<xref linkend="kate-part-line-modification"/>.</para>
<mediaobject>
1806
<imageobject><imagedata format="PNG" fileref="editor-colors-ModifiedLines.png"/></imageobject>
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
<caption><para></para></caption>
</mediaobject>
</listitem>
</varlistentry>

</variablelist>
</listitem>
</varlistentry>

<varlistentry id="variable-prefcolors-colors-text-decorations">
<term><guilabel>Text Decorations</guilabel></term>
<listitem>
<variablelist>

<varlistentry>
<term><userinput>SpellChecking</userinput> (<guilabel>Spelling Mistake Line</guilabel>)</term>
<listitem><para>This color is used to indicate spelling mistakes.</para>
<mediaobject>
1825
<imageobject><imagedata format="PNG" fileref="editor-colors-SpellChecking.png"/></imageobject>
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
<caption><para></para></caption>
</mediaobject>
</listitem>
</varlistentry>

<varlistentry>
<term><userinput>TabMarker</userinput> (<guilabel>Tab and Space Markers</guilabel>)</term>
<listitem><para>This color is used to draw white space indicators, when they are
enabled.</para>
<mediaobject>
1836
<imageobject><imagedata format="PNG" fileref="editor-colors-TabMarker.png"/></imageobject>
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
<caption><para></para></caption>
</mediaobject>
</listitem>
</varlistentry>

<varlistentry>
<term><userinput>IndentationLine</userinput> (<guilabel>Indentation Line</guilabel>)</term>
<listitem><para>This color is used to draw a line to the left of indented blocks,
if <link linkend="appearance-general">that feature is enabled</link>.</para>
<mediaobject>
1847
<imageobject><imagedata format="PNG" fileref="editor-colors-IndentationLine.png"/></imageobject>
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
<caption><para></para></caption>
</mediaobject>
</listitem>
</varlistentry>

<varlistentry>
<term><userinput>BracketMatching</userinput> (<guilabel>Bracket Highlight</guilabel>)</term>
<listitem><para>This color is used to draw the background of matching brackets.
</para>
<mediaobject>
1858
<imageobject><imagedata format="PNG" fileref="editor-colors-BracketMatching.png"/></imageobject>
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
<caption><para></para></caption>
</mediaobject>
</listitem>
</varlistentry>

</variablelist>
</listitem>
</varlistentry>

<varlistentry id="variable-prefcolors-colors-marker-colors">
<term><guilabel>Marker Colors</guilabel></term>
<listitem>
<variablelist>

<varlistentry>
<term><userinput>MarkBookmark</userinput> (<guilabel>Bookmark</guilabel>)</term>
<listitem><para>This color is used to indicate bookmarks. Note that this color
has an opacity of 22% (and 33% for the current line) with respect to the background.
For more information, see <xref linkend="kate-part-bookmarks"/>.</para>
<mediaobject>
1879
<imageobject><imagedata format="PNG" fileref="editor-colors-MarkBookmark.png"/></imageobject>
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
<caption><para></para></caption>
</mediaobject>
</listitem>
</varlistentry>

<varlistentry>
<term><userinput>MarkBreakpointActive</userinput> (<guilabel>Active Breakpoint</guilabel>)</term>
<listitem><para>This color is used by the GDB plugin to indicate an active
breakpoint. Notice that this color has an opacity to the background.
For more information, see <ulink url="help:/kate/kate-application-plugin-gdb.html">the
GDB Plugin documentation</ulink>.</para></listitem>
</varlistentry>

<varlistentry>
<term><userinput>MarkBreakpointReached</userinput> (<guilabel>Reached Breakpoint</guilabel>)</term>
<listitem><para>This color is used by the GDB plugin to indicate a breakpoint
you have reached while debugging. Notice that this color has an opacity
to the background.
For more information, see <ulink url="help:/kate/kate-application-plugin-gdb.html">the
GDB Plugin documentation</ulink>.</para></listitem>
</varlistentry>

<varlistentry>
<term><userinput>MarkBreakpointDisabled</userinput> (<guilabel>Disabled Breakpoint</guilabel>)</term>
<listitem><para>This color is used by the GDB plugin to indicate an inactive
breakpoint. Notice that this color has an opacity to the background.
For more information, see <ulink url="help:/kate/kate-application-plugin-gdb.html">the
GDB Plugin documentation</ulink>.</para></listitem>
</varlistentry>

<varlistentry>
<term><userinput>MarkExecution</userinput> (<guilabel>Execution</guilabel>)</term>
<listitem><para>This color is used by the GDB plugin the line presently being
executed. Notice that this color has an opacity to the background.
For more information, see <ulink url="help:/kate/kate-application-plugin-gdb.html">the
GDB Plugin documentation</ulink>.</para></listitem>
</varlistentry>

<varlistentry>
<term><userinput>MarkWarning</userinput> (<guilabel>Warning</guilabel>)</term>
<listitem><para>This color is used by the build plugin to indicate a line that
has caused a compiler warning. Notice that this color has an opacity to the background.
For more information, see <ulink url="help:/kate/kate-application-plugin-build.html">the
Build Plugin documentation</ulink>.</para></listitem>
</varlistentry>

<varlistentry>
<term><userinput>MarkError</userinput> (<guilabel>Error</guilabel>)</term>
<listitem><para>This color is used by the build plugin to indicate a line that
has caused a compiler error. Notice that this color has an opacity to the background.
For more information, see <ulink url="help:/kate/kate-application-plugin-build.html">the
Build Plugin documentation</ulink>.</para></listitem>
</varlistentry>

</variablelist>
</listitem>
</varlistentry>

<varlistentry id="variable-prefcolors-colors-text-templates-snippets">
<term><guilabel>Text Templates &amp; Snippets</guilabel></term>
<listitem>
<variablelist>

<varlistentry>
<term><userinput>TemplateBackground</userinput> (<guilabel>Background</guilabel>)</term>
<listitem><para>This color is used by the &kate; Snippets plugin to mark the
background of a snippet.  For more information, see
<ulink url="help:/kate/kate-application-plugin-snippets.html">the &kate; Snippets
documentation</ulink>.</para></listitem>
</varlistentry>

<varlistentry>
<term><userinput>TemplatePlaceholder</userinput> (<guilabel>Editable Placeholder</guilabel>)</term>
<listitem><para>This color is used by the &kate; Snippets plugin to mark a
placeholder that you can click in to edit manually.  For more information, see
<ulink url="help:/kate/kate-application-plugin-snippets.html">the &kate; Snippets
documentation</ulink>.</para></listitem>
</varlistentry>

<varlistentry>
<term><userinput>TemplateFocusedPlaceholder</userinput> (<guilabel>Focused Editable Placeholder</guilabel>)</term>
<listitem><para>This color is used by the &kate; Snippets plugin to mark the
placeholder that you are presently editing.  For more information, see
<ulink url="help:/kate/kate-application-plugin-snippets.html">the &kate; Snippets
documentation</ulink>.</para>
<mediaobject>
1966
<imageobject><imagedata format="PNG" fileref="editor-colors-Template.png"/></imageobject>
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
<caption><para></para></caption>
</mediaobject>
</listitem>
</varlistentry>

<varlistentry>
<term><userinput>TemplateReadOnlyPlaceholder</userinput> (<guilabel>Not Editable Placeholder</guilabel>)</term>
<listitem><para>This color is used by the &kate; Snippets plugin to mark a
placeholder that cannot be edited manually, such as one that is automatically
populated.  For more information, see
<ulink url="help:/kate/kate-application-plugin-snippets.html">the &kate; Snippets
documentation</ulink>.</para>
<mediaobject>
1980
<imageobject><imagedata format="PNG" fileref="editor-colors-TemplateReadOnlyPlaceholder.png"/></imageobject>
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
<caption><para></para></caption>
</mediaobject>
</listitem>
</varlistentry>

</variablelist>
</listitem>
</varlistentry>

</variablelist>

</sect3>

<sect3 id="color-themes-text-styles">

<title>Default Text Styles</title>

<para>The default text styles are inherited by the highlight text styles, allowing
the editor to present text in a very consistent way, for example comment text is using
the same style in almost all of the text formats that KSyntaxHighlighting can highlight.
</para>

<note>
2004
<para>
Yuri Chornoivan's avatar
Yuri Chornoivan committed
2005
These text styles can be referenced from the <userinput>default styles</userinput> used
2006
2007
2008
2009
in <link linkend="highlight">syntax highlighting</link> definition &XML; files, for example,
the <quote>Normal</quote> attribute is equivalent to <quote>dsNormal</quote> in the &XML; files,
and <quote>DataType</quote> is equivalent to <quote>dsDataType</quote>.
See <xref linkend="kate-highlight-default-styles"/> in the syntax highlighting documentation.
2010
</para>
2011
2012
2013
</note>

<tip>
2014
<para>
2015
2016
2017
Make sure to choose readable colors with good contrast especially in combination with
the <userinput><link linkend="color-themes-editor-colors">Editor Colors</link></userinput>.
See <xref linkend="color-themes-contrast"/>.
2018
</para>
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
</tip>

<para>In the <link linkend="color-themes-json">&JSON; file</link>, the respective key
<userinput>text-styles</userinput> has as value an <emphasis>object</emphasis> where
each key corresponds to the name of a <emphasis>default text style</emphasis>, which are
equivalent to those used in the syntax highlighting definitions. Here, <userinput>all available
text style keys are mandatory</userinput>, these are listed below.
</para>

<programlisting>
"text-styles": {
    "Normal" : {
        "text-color" : "#1f1c1b",
        "selected-text-color" : "#ffffff",
        "bold" : false,
        "italic" : false,
        "underline" : false,
        "strike-through" : false
    },
    "Keyword" : {
        "text-color" : "#1f1c1b",
        "selected-text-color" : "#ffffff",
        "bold" : true
    },
    "Function" : {
        "text-color" : "#644a9b",
        "selected-text-color" : "#452886"
    },
    <replaceable>The other text style keys...</replaceable>
}
</programlisting>

2051
2052
2053
2054
<variablelist>
<varlistentry>

<term>Each key of <emphasis>default text style</emphasis> has a &JSON; object as
2055
2056
its value, where values such as <emphasis>color</emphasis>, <emphasis>bold</emphasis>,
<emphasis>italic</emphasis>, etc. are specified. These keys are as follows: