Coder Social home page Coder Social logo

snipmedev / highlights Goto Github PK

View Code? Open in Web Editor NEW
58.0 1.0 2.0 343 KB

Kotlin Multiplatform (KMM) syntax highlighting engine

License: Apache License 2.0

Kotlin 100.00%
engine kmm kmm-library kotlin kotlin-multiplatform syntax-analysis syntax-highlighting syntax-theme

highlights's Introduction

highlights_banner_opaque

Maven Central Kotlin GitHub License

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
  • #EDEDED Code
  • #CC7832 Keyword
  • #6A8759 String
  • #6897BB Literal
  • #909090 Comment
  • #BBB529 Metadata
  • #629755 Multiline Comment
  • #CC7832 Punctuation
  • #EDEDED Mark
  • #F8F8F2 Code
  • #F92672 Keyword
  • #E6DB74 String
  • #AE81FF Literal
  • #FD971F Comment
  • #B8F4B8 Metadata
  • #FD971F Multiline Comment
  • #F8F8F2 Punctuation
  • #F8F8F2 Mark
  • #000080 Code
  • #0000FF Keyword
  • #808080 String
  • #FF8000 Literal
  • #008000 Comment
  • #000080 Metadata
  • #008000 Multiline Comment
  • #AA2C8C Punctuation
  • #AA2C8C Mark
  • #008500 Code
  • #008500 Keyword
  • #269926 String
  • #39E639 Literal
  • #67E667 Comment
  • #008500 Metadata
  • #67E667 Multiline Comment
  • #008500 Punctuation
  • #008500 Mark
  • #DFDEE0 Code
  • #729FCF Keyword
  • #93CF55 String
  • #8AE234 Literal
  • #888A85 Comment
  • #5DB895 Metadata
  • #888A85 Multiline Comment
  • #CB956D Punctuation
  • #CB956D Mark
  • #DFDEE0 Code
  • #729FCF Keyword
  • #93CF55 String
  • #8AE234 Literal
  • #888A85 Comment
  • #5DB895 Metadata
  • #888A85 Multiline Comment
  • #CB956D Punctuation
  • #CB956D Mark

Light 🌞

Darcula Monokai Notepad Matrix Pastel Atom One
  • #121212 Code
  • #CC7832 Keyword
  • #6A8759 String
  • #6897BB Literal
  • #909090 Comment
  • #BBB529 Metadata
  • #629755 Multiline Comment
  • #CC7832 Punctuation
  • #121212 Mark
  • #07070D Code
  • #F92672 Keyword
  • #E6DB74 String
  • #AE81FF Literal
  • #FD971F Comment
  • #B8F4B8 Metadata
  • #FD971F Multiline Comment
  • #07070D Punctuation
  • #07070D Mark
  • #000080 Code
  • #0000FF Keyword
  • #808080 String
  • #FF8000 Literal
  • #008000 Comment
  • #000080 Metadata
  • #008000 Multiline Comment
  • #AA2C8C Punctuation
  • #AA2C8C Mark
  • #008500 Code
  • #008500 Keyword
  • #269926 String
  • #39E639 Literal
  • #67E667 Comment
  • #008500 Metadata
  • #67E667 Multiline Comment
  • #008500 Punctuation
  • #008500 Mark
  • #20211F Code
  • #729FCF Keyword
  • #93CF55 String
  • #8AE234 Literal
  • #888A85 Comment
  • #5DB895 Metadata
  • #888A85 Multiline Comment
  • #CB956D Punctuation
  • #CB956D Mark
  • #DFDEE0 Code
  • #729FCF Keyword
  • #93CF55 String
  • #8AE234 Literal
  • #888A85 Comment
  • #5DB895 Metadata
  • #888A85 Multiline Comment
  • #CB956D Punctuation
  • #CB956D Mark

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 🚧

  • 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.