Warning, /frameworks/syntax-highlighting/README.md is written in an unsupported language. File is not indexed.

0001 # Syntax Highlighting
0002 
0003 Syntax highlighting engine for Kate syntax definitions
0004 
0005 ## Table of contents
0006 
0007 1. [Introduction](#introduction)
0008 2. [Out of scope](#out-of-scope)
0009 3. [Syntax definition files](#syntax-definition-files)
0010 4. [Color theme files](#color-theme-files)
0011 5. [Build it](#build-it)
0012 6. [How to contribute](#how-to-contribute)
0013    * [Licensing](#licensing)
0014    * [Tips for contributing to syntax definition files](#tips-for-contributing-to-syntax-definition-files)
0015    * [Adding unit tests for a syntax definition](#adding-unit-tests-for-a-syntax-definition)
0016 7. [Report bug or help to fix them](#report-bug-or-help-to-fix-them)
0017 8. [Updating the syntax & themes pages of the kate-editor.org website](#updating-the-kate-editororgsyntax-website)
0018 
0019 ## Introduction
0020 
0021 This is a stand-alone implementation of the Kate syntax highlighting engine.
0022 It's meant as a building block for text editors as well as for simple highlighted
0023 text rendering (e.g. as HTML), supporting both integration with a custom editor
0024 as well as a ready-to-use QSyntaxHighlighter sub-class.
0025 
0026 Besides a C++ API, a [QML API](@ref qml_api) is also provided.
0027 
0028 ## Out of scope
0029 
0030 To not turn this into yet another text editor, the following things are considered
0031 out of scope:
0032 
0033 * code folding, beyond providing folding range information
0034 * auto completion
0035 * spell checking
0036 * user interface for configuration
0037 * management of text buffers or documents
0038 
0039 If you need any of this, check out [KTextEditor](https://api.kde.org/frameworks/ktexteditor/html/).
0040 
0041 ## Syntax definition files
0042 
0043 This library uses Kate syntax definition files for the actual highlighting,
0044 the file format is documented [here](https://docs.kde.org/?application=katepart&branch=stable5&path=highlight.html).
0045 
0046 More than 300 syntax definition files are included, that are located
0047 in **data/syntax/** and have the **.xml** extension. Additional ones are
0048 picked up from the file system if present, so you can easily extend this
0049 by application-specific syntax definitions for example.
0050 
0051 To install or test a syntax definition file locally, place it in
0052 **org.kde.syntax-highlighting/syntax/**, which is located in your user directory.
0053 Usually it is:
0054 
0055 <table>
0056     <tr>
0057         <td>For local user</td>
0058         <td>$HOME/.local/share/org.kde.syntax-highlighting/syntax/</td>
0059     </tr>
0060     <tr>
0061         <td>For Flatpak packages</td>
0062         <td>$HOME/.var/app/<em>package-name</em>/data/org.kde.syntax-highlighting/syntax/</td>
0063     </tr>
0064     <tr>
0065         <td>For Snap packages</a></td>
0066         <td>$HOME/snap/<em>package-name</em>/current/.local/share/org.kde.syntax-highlighting/syntax/</td>
0067     </tr>
0068     <tr>
0069         <td>On Windows®</td>
0070         <td>&#37;USERPROFILE&#37;&#92;AppData&#92;Local&#92;org.kde.syntax-highlighting&#92;syntax&#92;</td>
0071     </tr>
0072     <tr>
0073         <td>On macOS®</td>
0074         <td>$HOME/Library/Application Support/org.kde.syntax-highlighting/syntax/</td>
0075     </tr>
0076 </table>
0077 
0078 For more details, see ["The Highlight Definition XML Format" (Working with Syntax Highlighting, KDE Documentation)](https://docs.kde.org/?application=katepart&branch=stable5&path=highlight.html#katehighlight-xml-format).
0079 
0080 Also, in **data/schema/** there is a script to validate the syntax definition XML
0081 files. Use the command `validatehl.sh mySyntax.xml`.
0082 
0083 ## Color theme files
0084 
0085 This library includes the color themes, which are documented
0086 [here](https://docs.kde.org/?application=katepart&branch=stable5&path=color-themes.html).
0087 
0088 The color theme files use the JSON format and are located in **data/themes/**
0089 with the **.theme** extension.
0090 Additional ones are also picked up from the file system if present,
0091 in the **org.kde.syntax-highlighting/themes/** folder of your user directory,
0092 allowing you to easily add custom color theme files. This location is the same
0093 as shown in the table of the [previous section](#syntax-definition-files),
0094 replacing the **syntax** folder with **themes**.
0095 For more details, see ["The Color Themes JSON Format" (Working with Color Themes, KDE Documentation)](https://docs.kde.org/?application=katepart&branch=stable5&path=color-themes.html#color-themes-json).
0096 
0097 The [KTextEditor](https://api.kde.org/frameworks/ktexteditor/html/) library
0098 (used by Kate, Kile and KDevelop, for example) provides a
0099 [user interface](https://docs.kde.org/?application=katepart&branch=stable5&path=color-themes.html#color-themes-gui)
0100 for editing and creating KSyntaxHighlighting color themes, including
0101 a tool for exporting and importing the JSON theme files.
0102 
0103 Note that in KDE text editors, the KSyntaxHighlighting color themes are used
0104 [since KDE Frameworks 5.75](https://kate-editor.org/post/2020/2020-09-13-kate-color-themes-5.75/),
0105 released on October 10, 2020. Previously, Kate's color schemes
0106 (KConfig based schema config) were used and are now deprecated.
0107 The tool **utils/schema-converter/** and the script **utils/kateschema_to_theme_converter.py**
0108 convert the old Kate schemas to KSyntaxHighlighting themes.
0109 
0110 Also see ["Submit a KSyntaxHighlighting Color Theme" (Kate Editor Website)](https://kate-editor.org/post/2020/2020-09-18-submit-a-ksyntaxhighlighting-color-theme/).
0111 
0112 ## Build it
0113 
0114 1. Create and change into a build directory. Usually, a folder called **build**
0115    is created inside the **syntax-highlighting** source directory.
0116 
0117    ```bash
0118    mkdir <build-directory>
0119    cd <build-directory>
0120    ```
0121 
0122 2. Run the configure process with *cmake* and compile:
0123 
0124    ```bash
0125    cmake <source-directory>
0126    make
0127    ```
0128 
0129    For example:
0130 
0131    ```bash
0132    git clone git@invent.kde.org:frameworks/syntax-highlighting.git
0133    mkdir ./syntax-highlighting/build
0134    cd ./syntax-highlighting/build
0135    cmake ../
0136    make
0137    ```
0138 
0139    For more details see ["Building Kate from Sources on Linux" (Kate Editor Website)](https://kate-editor.org/build-it/).
0140 
0141    **NOTE:** If running *cmake* shows an error related to your version of KDE
0142    Frameworks, you edit the **CMakeLists.txt** file in the line
0143    `find_package(ECM 5.XX.X ...)`.
0144 
0145 3. To run tests:
0146 
0147    ```bash
0148    make test
0149    ```
0150 
0151    The tests are located in the **autotests** directory.
0152    This command can be used to check changes to units test after modifying some
0153    syntax definition file. To add a unit test or update the references, see the
0154    section ["Adding unit tests for a syntax definition"](#adding-unit-tests-for-a-syntax-definition).
0155 
0156 ## How to contribute
0157 
0158 KDE uses a GitLab instance at **invent.kde.org** for code review. The official
0159 repository of the KSyntaxHighlighting framework is [here](https://invent.kde.org/frameworks/syntax-highlighting).
0160 
0161 All the necessary information to send contributions is [here](https://community.kde.org/Infrastructure/GitLab).
0162 
0163 ### Licensing
0164 
0165 Contributions to KSyntaxHighlighting shall be licensed under [MIT](LICENSES/MIT.txt).
0166 
0167 All files shall contain a proper "SPDX-License-Identifier: MIT" identifier inside a header like:
0168 
0169 ```cpp
0170 /*
0171     SPDX-FileCopyrightText: 2020 Christoph Cullmann <cullmann@kde.org>
0172 
0173     SPDX-License-Identifier: MIT
0174 */
0175 ```
0176 
0177 ### Tips for contributing to syntax definition files
0178 
0179 * If you are modifying an existing syntax definition XML file, you must increase
0180   the version number of the language.
0181 
0182 * Do not use hard-coded colors, as they may not look good or be illegible in some color
0183   themes. Prefer to use the default color styles.
0184 
0185   For more information, see:
0186 
0187     * [Available Default Styles (Working with Syntax Highlighting, KDE Documentation)](https://docs.kde.org/?application=katepart&branch=stable5&path=highlight.html#kate-highlight-default-styles)
0188     * [Kate Part (KF5): New Default Styles for better Color Schemes (Kate Editor Website)](https://kate-editor.org/2014/03/07/kate-part-kf5-new-default-styles-for-better-color-schemes/)
0189 
0190 * While writing syntax, you can use `ksyntaxhighlighter6` (previously named `kate-syntax-highlighter`) to display the style or others informations associated with each part of text. For example `ksyntaxhighlighter6 --output-format=ansi --syntax-trace=format test.cpp`.
0191 
0192 * Add test files, these are found in **autotests/input/**.
0193   If you are going to add a new syntax XML file, create a new test file; if you
0194   are going to modify a XML file, adds examples to existing test files.
0195 
0196   Then, it is necessary to generate and update the files in **autotests/folding/**,
0197   **autotests/html/** and **autotests/reference/**, which must be included in the
0198   patches. Instructions are [below](#adding-unit-tests-for-a-syntax-definition).
0199 
0200 ### Adding unit tests for a syntax definition
0201 
0202 1. Add an input file into the **autotests/input/** folder, lets call it
0203    **test.&lt;language-extension&gt;**.
0204 
0205 2. If the file extension is not sufficient to trigger the right syntax definition, you can add an
0206    second file **testname.&lt;language-extension&gt;.syntax** that contains the syntax definition name
0207    to enforce the use of the right extension.
0208 
0209 3. Do `make && make test`.
0210 
0211    Note that after adding or modifying something in
0212    **&lt;source-directory&gt;/autotests/input/**, an error will be showed when
0213    running `make test`, because the references in the source directory do not
0214    match the ones now generated.
0215 
0216 4. Inspect the outputs found in your binary directory **autotests/folding.out/**,
0217    **autotests/html.output/** and **autotests/output/**.
0218 
0219 5. If OK, run in the binary folder `./autotests/update-reference-data.sh`
0220    to copy the results to the right location.
0221    That script updates the references in the source directory in
0222    **autotest/folding/**, **autotest/html/** and **autotest/reference/**.
0223 
0224 6. Add the result references after the copying to the git.
0225 
0226 ## Report bug or help to fix them
0227 
0228 KDE uses Bugzilla to management of bugs at **bugs.kde.org**. You can see the bugs
0229 reported of **frameworks-syntax-highlighting** [here](https://bugs.kde.org/describecomponents.cgi?product=frameworks-syntax-highlighting).
0230 
0231 Also, you can report a bug [here](https://bugs.kde.org/enter_bug.cgi?product=frameworks-syntax-highlighting).
0232 
0233 However, some users often report bugs related to syntax highlighting in
0234 [kate/syntax](https://bugs.kde.org/buglist.cgi?component=syntax&product=kate&resolution=---)
0235 and [kile/editor](https://bugs.kde.org/buglist.cgi?component=editor&product=kile&resolution=---).
0236 
0237 ## Updating the syntax & themes pages of the kate-editor.org website
0238 
0239 To update the [kate-editor.org/syntax](https://kate-editor.org/syntax/) and
0240 [kate-editor.org/themes](https://kate-editor.org/themes/) websites
0241 including the update site & all linked examples/files,
0242 please run after successful **build** & **test** the following make target:
0243 
0244 ```bash
0245 make update_kate_editor_org
0246 ```
0247 
0248 This will clone the [kate-editor.org git](https://invent.kde.org/websites/kate-editor-org)
0249 from *invent.kde.org* into **kate-editor-org** inside the build directory and update the needed things.
0250 
0251 You can afterwards step into **kate-editor-org** and commit & push the change after review.
0252 
0253 The [kate-editor.org](https://kate-editor.org) webserver will update itself periodically from the repository on *invent.kde.org*.