Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wingio/syntakts
Simple to use text parser and syntax highlighter for Kotlin Multiplatform
https://github.com/wingio/syntakts
abstract-syntax-tree android android-library ast compose compose-library compose-multiplatform hacktoberfest kmp kotlin kotlin-library kotlin-multiplatform text-processing
Last synced: 3 months ago
JSON representation
Simple to use text parser and syntax highlighter for Kotlin Multiplatform
- Host: GitHub
- URL: https://github.com/wingio/syntakts
- Owner: wingio
- License: mit
- Created: 2023-10-10T13:53:59.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-07-24T19:55:17.000Z (6 months ago)
- Last Synced: 2024-07-25T03:55:20.552Z (6 months ago)
- Topics: abstract-syntax-tree, android, android-library, ast, compose, compose-library, compose-multiplatform, hacktoberfest, kmp, kotlin, kotlin-library, kotlin-multiplatform, text-processing
- Language: Kotlin
- Homepage: http://syntakts.wingio.xyz
- Size: 577 KB
- Stars: 19
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
### Simple to use text parser and syntax highlighter for Kotlin Multiplatform
[![Maven Central](https://img.shields.io/maven-central/v/xyz.wingio.syntakts/syntakts-core?style=for-the-badge&logo=apachemaven&label=Latest&labelColor=black&color=blue)](https://central.sonatype.com/namespace/xyz.wingio.syntakts)
[![GitHub Repo stars](https://img.shields.io/github/stars/wingio/syntakts?style=for-the-badge&logo=github&labelColor=black&color=red)](https://github.com/wingio/syntakts/stargazers)
[![GitHub Sponsors](https://img.shields.io/github/sponsors/wingio?style=for-the-badge&logo=githubsponsors&labelColor=black&color=pink)](https://github.com/sponsors/wingio)---
## Setup
```kotlin
implementation("xyz.wingio.syntakts:syntakts-core:$syntaktsVersion")
// implementation("xyz.wingio.syntakts:syntakts-compose:$syntaktsVersion")
// implementation("xyz.wingio.syntakts:syntakts-compose-material3:$syntaktsVersion")
```## Use
Syntakts can be set up through a simple DSL:
```kotlin
val mySyntakts = syntakts {
rule("@([A-z])") { result, context ->
append(result.groupValues[1]) {
color = Color.Yellow
}
}
}
```We also provide MarkdownSyntakts and BasicMarkdownSyntakts, which has some default markdown rules
### Context
Syntakts allows you to pass any class as context, this can be used to pass additional information for rendering.
If you don't need to use context you can set it to UnitExample:
```kotlin
data class Context(
val userMap = mapOf("1234" to "Wing")
)val mySytankts = syntakts {
rule("<@([0-9]+)>") { result, context ->
val username = context.userMap[result.groupValues[1]] ?: "Unknown"
append("@$username") {
color = Color.Yellow
}
}
}
```## Displaying
### Compose
Artifact: `syntakts-compose`Syntakts uses AnnotatedStrings in order to display rendered text in Compose
> [!NOTE]
>
> When creating a Syntakts instance in a composable we reccommend replacing `syntakts {}` with `rememberSyntakts {}`Example:
```kotlin
@Composable
fun SomeScreen() {
val syntakts = rememberSyntakts { /* */ }Text(
text = syntakts.rememberRendered("some input")
)
}
```### Android
Artifact: `syntakts-android`Syntakts uses SpannableStrings in order to display rendered text on Android
Example:
```kotlin
val syntakts = syntakts { /* */ }findViewById(R.id.my_text_view).render("some input", syntakts)
```#### Clickable
Syntakts for Compose includes a ClickableText component that is neccessary in order to handle clickable text. The `syntakts-compose-material3` includes this component as well but adds support for Material 3 themingSyntakts for Android requires that the TextView have its movementMethod set to our ClickableMovementMethod
## Attribution
Syntakts was heavily inspired by [SimpleAST](https://github.com/discord/SimpleAST), an unfortunately abandoned library that was once used in Discords android app