Highlights
Highlights copied to clipboard
Kotlin Multiplatform (KMM) syntax highlighting engine
Highlights
Kotlin Multiplatform syntax highlighting engine.
Installation ⬇️
repositories {
mavenCentral()
}
implementation("dev.snipme:highlights:0.9.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 📱 💻 🖥️
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 {}")
// Keywords = [public, class], Marks = [{, }]
getCodeStructure()
// BoldHighlight, ColorHighlight
getHighlights()
}
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.
Languages 🌍
C,
C++,
DART,
JAVA,
KOTLIN,
RUST,
C#,
COFFEESCRIPT,
JAVASCRIPT,
PERL,
PYTHON,
RUBY,
SHELL,
SWIFT,
TYPESCRIPT,
GO,
PHP
Themes 🖌️
The library comes with predefined syntax coloring themes available in SyntaxThemes:
Dark 🌚
| Darcula | Monokai | Notepad | Matrix | Pastel | Atom One |
|---|---|---|---|---|---|
|
|
|
|
|
|
Light 🌞
| 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
)
Popular uses 🙌
If your project uses this code, please write me or add your info
| Type | Name |
|---|---|
| Library | KodeView |
| Application | SnippLog |
| Application | FlowMVI Sample |
TODO 🚧
- [X] Migrate some lists to sets
- [ ] Optimize code analysis
- [ ] Add more themes and languages
- [ ] Support italic and underline text style
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 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.
Code
Keyword
String
Literal
Comment
Metadata
Multiline Comment
Code
Keyword
String
Literal
Comment
Metadata
Code
Keyword
String
Literal
Comment
Punctuation
Code
String
Literal
Comment
Code
Keyword
String
Literal
Comment
Metadata
Punctuation
Code
Keyword
String
Literal
Comment
Metadata
Punctuation
Mark
Code
Code
Code
Code
Keyword
String
Literal
Comment
Metadata
Punctuation
Mark