

Highlights
Kotlin Multiplatform syntax highlighting engine.
Installation ⬇️
repositories {
mavenCentral()
}
implementation("dev.snipme:highlights:1.1.0")
Features ✨
- 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
Support ☕
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
Usage ✍️
💡 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 {}")
getCodeStructure()
getHighlights()
}
There is also a possibility to handle result asynchronously
highlights.getHighlightsAsync(
object : DefaultHighlightsResultListener() {
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))
.build()
.run {
getHighlights()
}
More advance usage of this library is shown here.
Languages 🌍
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
Themes 🖌️
The library comes with predefined syntax coloring themes available in SyntaxThemes:
Dark 🌚
Light 🌞
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
)
Popular uses 🙌
If your project uses this code, please write me or add your info
TODO 🚧
Contribution 💻
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
License 🖋️
Copyright 2023-2024 Tomasz Kądziołka.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this except compliance the License.
You may obtain a copy of the License at
http:
Unless applicable law agreed to writing, software
distributed under the License distributed an BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express implied.
See the License the specific language governing permissions
limitations under the License.