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=trunk5&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>%USERPROFILE%\AppData\Local\org.kde.syntax-highlighting\syntax\</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=trunk5&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=trunk5&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=trunk5&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=trunk5&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=trunk5&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 * Add test files, these are found in **autotests/input/**. 0191 If you are going to add a new syntax XML file, create a new test file; if you 0192 are going to modify a XML file, adds examples to existing test files. 0193 0194 Then, it is necessary to generate and update the files in **autotests/folding/**, 0195 **autotests/html/** and **autotests/reference/**, which must be included in the 0196 patches. Instructions are [below](#adding-unit-tests-for-a-syntax-definition). 0197 0198 ### Adding unit tests for a syntax definition 0199 0200 1. Add an input file into the **autotests/input/** folder, lets call it 0201 **test.<language-extension>**. 0202 0203 2. If the file extension is not sufficient to trigger the right syntax definition, you can add an 0204 second file **testname.<language-extension>.syntax** that contains the syntax definition name 0205 to enforce the use of the right extension. 0206 0207 3. Do `make && make test`. 0208 0209 Note that after adding or modifying something in 0210 **<source-directory>/autotests/input/**, an error will be showed when 0211 running `make test`, because the references in the source directory do not 0212 match the ones now generated. 0213 0214 4. Inspect the outputs found in your binary directory **autotests/folding.out/**, 0215 **autotests/html.output/** and **autotests/output/**. 0216 0217 5. If OK, run in the binary folder `./autotests/update-reference-data.sh` 0218 to copy the results to the right location. 0219 That script updates the references in the source directory in 0220 **autotest/folding/**, **autotest/html/** and **autotest/reference/**. 0221 0222 6. Add the result references after the copying to the git. 0223 0224 ## Report bug or help to fix them 0225 0226 KDE uses Bugzilla to management of bugs at **bugs.kde.org**. You can see the bugs 0227 reported of **frameworks-syntax-highlighting** [here](https://bugs.kde.org/describecomponents.cgi?product=frameworks-syntax-highlighting). 0228 0229 Also, you can report a bug [here](https://bugs.kde.org/enter_bug.cgi?product=frameworks-syntax-highlighting). 0230 0231 However, some users often report bugs related to syntax highlighting in 0232 [kate/syntax](https://bugs.kde.org/buglist.cgi?component=syntax&product=kate&resolution=---) 0233 and [kile/editor](https://bugs.kde.org/buglist.cgi?component=editor&product=kile&resolution=---). 0234 0235 ## Updating the syntax & themes pages of the kate-editor.org website 0236 0237 To update the [kate-editor.org/syntax](https://kate-editor.org/syntax/) and 0238 [kate-editor.org/themes](https://kate-editor.org/themes/) websites 0239 including the update site & all linked examples/files, 0240 please run after successful **build** & **test** the following make target: 0241 0242 ```bash 0243 make update_kate_editor_org 0244 ``` 0245 0246 This will clone the [kate-editor.org git](https://invent.kde.org/websites/kate-editor-org) 0247 from *invent.kde.org* into **kate-editor-org** inside the build directory and update the needed things. 0248 0249 You can afterwards step into **kate-editor-org** and commit & push the change after review. 0250 0251 The [kate-editor.org](https://kate-editor.org) webserver will update itself periodically from the repository on *invent.kde.org*.