Kotlin Multiplatform syntax highlighting engine.
repositories {
mavenCentral()
}
implementation("dev.snipme:highlights:1.0.0")
- Code component analysis (Keyword, comment, etc.)
- Multiple syntax languages (Java, Swift, Kotlin, C, ...)
- Themes
- Text bolding (emphasis)
- Result caching and support for incremental changes
- Written in pure Kotlin, so available for many platforms 📱 💻 🖥️
- Sync or async mode
Kotlin Multiplatform is a fresh environment and developing for it is neither fast nor easy 🥲
If you feel that any of our project has saved you a time or effort, then consider supporting us via:
🧋 Buy Me A Coffee
💡 As each Highlights instance caches code analysis, it is recommended to re-use the same instance for small code changes.
To start, simply put any code snippet in the default builder
Highlights.default().apply {
setCode("public class ExampleClass {}")
// Keywords = [public, class], Marks = [{, }]
getCodeStructure()
// BoldHighlight, ColorHighlight
getHighlights()
}
There is also a possibility to handle result asynchronously
highlights.getHighlightsAsync(
object : DefaultHighlightsResultListener() {
// onStart
// onError
// onCancel
override fun onSuccess(result: List<CodeHighlight>) {
emitResult(highlights)
}
}
)
You can also set language, theme and phrase emphasis. Language and theme has impact on the ColorHighlight and emphasis is represented by the BoldHighlight.
Highlights.Builder()
.code("public class ExampleClass {}")
.theme(SyntaxThemes.monokai())
.language(SyntaxLanguage.JAVA)
.emphasis(PhraseLocation(13, 25)) // ExampleClass
.build()
.run {
getHighlights()
}
More advance usage of this library is shown here.
C
,
C++
,
DART
,
JAVA
,
KOTLIN
,
RUST
,
C#
,
COFFEESCRIPT
,
JAVASCRIPT
,
PERL
,
PYTHON
,
RUBY
,
SHELL
,
SWIFT
,
TYPESCRIPT
,
GO
,
PHP
The library comes with predefined syntax coloring themes available in SyntaxThemes
:
Darcula | Monokai | Notepad | Matrix | Pastel | Atom One |
---|---|---|---|---|---|
Darcula | Monokai | Notepad | Matrix | Pastel | Atom One |
---|---|---|---|---|---|
You can also prepare your own themes and use them. Just create the SyntaxTheme
class:
SyntaxTheme(
key = "MY_THEME",
code = 0xEDEDED,
keyword = 0xCC7832,
string = 0x6A8759,
literal = 0x6897BB,
comment = 0x909090,
metadata = 0xBBB529,
multilineComment = 0x629755,
punctuation = 0xCC7832,
mark = 0xEDEDED
)
If your project uses this code, please write me or add your info
Type | Name |
---|---|
Library | KodeView |
Application | SnippLog |
Application | FlowMVI Sample |
- Migrate some lists to sets
- Optimize code analysis
- Add more themes and languages
- Support italic and underline text style
Any form of support is very welcomed.
Bugs, problems and new feature requests should be placed in the Issues
tab with proper labeling.
New feature can be also submitted via Pull Requests
.
Then make sure:
- Current and added tests have passed
- CHANGELOG and README have been updated
- New code matches library's vision and code style
Copyright 2023-2024 Tomasz Kądziołka.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.