Skip to content

Commit

Permalink
Creates sample module and generates readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jisungbin committed Jul 2, 2024
1 parent ddd0fd2 commit 06592b3
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 15 deletions.
41 changes: 28 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
## Compose Markdown

Build markdown with Jetpack Compose _[runtime_](https://developer.android.com/jetpack/androidx/releases/compose-runtime).[^UI]

> This README is made with Composable! Check out the [sample](/sample/src/main/kotlin/main.kt).
### Introduction

Jetpack Compose is often known as a UI toolkit, but it is actually a library providing excellent
node traversal implementation. This repository creates our own Compose UI that produces Markdown
strings using only Compose's Runtime features.

This development began with the purpose of learning Compose Runtime and has been made public to
spread the value of the Compose Runtime.

You can generate markdown programmatically using the power of `Kotlin + Composable`.

```kotlin
markdown {
H1("Hello, Compose-Markdown!")
Quote(
modifier = Modifier.clickable("https://github.com/jisungbin/compose-markdown"),
text = buildAnnotatedString {
append("Build ")
withStyle(TextStyle(italic = true)) { append("Markdown") }
append(" with ")
withStyle(TextStyle(fontWeight = FontWeight.Bold)) { append("Jetpack Compose runtime") }
append("!")
},
)
List(ordered = true) {
repeat(3) {
Text("My item!")
}
}
```

WIP
1. My item!
2. My item!
3. My item!

### Download

Will be published to MavenCentral soon.

[^UI]: **Not Compose UI!**
2 changes: 1 addition & 1 deletion markdown-runtime/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ kotlin {

dependencies {
implementation(libs.androidx.annotation)
implementation(libs.compose.runtime)
api(libs.compose.runtime)

api(libs.kotlin.coroutines)

Expand Down
2 changes: 1 addition & 1 deletion markdown-ui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies {
implementation(libs.compose.runtime)
implementation(libs.androidx.annotation)

implementation(projects.markdownRuntime)
api(projects.markdownRuntime)

testImplementation(kotlin("test-junit5"))
testImplementation(libs.test.assertk)
Expand Down
21 changes: 21 additions & 0 deletions sample/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Developed by Ji Sungbin 2024.
*
* Licensed under the MIT.
* Please see full license: https://github.com/jisungbin/compose-markdown/blob/main/LICENSE
*/

plugins {
kotlin("jvm")
alias(libs.plugins.kotlin.compose)
}

kotlin {
sourceSets.all {
languageSettings.enableLanguageFeature("ExplicitBackingFields")
}
}

dependencies {
implementation(projects.markdownUi)
}
80 changes: 80 additions & 0 deletions sample/src/main/kotlin/main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Developed by Ji Sungbin 2024.
*
* Licensed under the MIT.
* Please see full license: https://github.com/jisungbin/compose-markdown/blob/main/LICENSE
*/

import kotlinx.coroutines.runBlocking
import land.sungbin.markdown.runtime.markdown
import land.sungbin.markdown.ui.list.List
import land.sungbin.markdown.ui.modifier.Modifier
import land.sungbin.markdown.ui.modifier.clickable
import land.sungbin.markdown.ui.modifier.footnote
import land.sungbin.markdown.ui.quote.Quote
import land.sungbin.markdown.ui.text.Code
import land.sungbin.markdown.ui.text.H2
import land.sungbin.markdown.ui.text.H3
import land.sungbin.markdown.ui.text.Text
import land.sungbin.markdown.ui.text.TextStyle
import land.sungbin.markdown.ui.text.buildAnnotatedString

fun main() = runBlocking {
val readme = markdown {
H2("Compose Markdown")
Text("")
Text(
buildAnnotatedString {
append("Build markdown with Jetpack Compose ")
withStyle(TextStyle(italics = true)) { "runtime" }
append(".")
},
modifier = Modifier
.clickable("https://developer.android.com/jetpack/androidx/releases/compose-runtime") { text ->
text.indexOf("runtime").let { it..it + "runtime".length }
}
.footnote("UI", position = { it.length - 1 }) {
Text(buildAnnotatedString { withStyle(TextStyle(bold = true)) { "Not Compose UI!" } })
},
)
Text("")
Quote {
Text(
"This README is made with Composable! Check out the sample.",
modifier = Modifier.clickable("/sample/src/main/kotlin/main.kt") { text ->
text.indexOf("sample").let { it..<it + "sample".length }
},
)
}
Text("")
H3("Introduction")
Text("")
Text("Jetpack Compose is often known as a UI toolkit, but it is actually a library providing excellent ")
Text("node traversal implementation. This repository creates our own Compose UI that produces Markdown ")
Text("strings using only Compose's Runtime features.")
Text("")
Text("This development began with the purpose of learning Compose Runtime and has been made public to ")
Text("spread the value of the Compose Runtime.")
Text("")
Text("You can generate markdown programmatically using the power of `Kotlin + Composable`.")
Text("")
Code("kotlin") {
Text("List(ordered = true) {")
Text(" repeat(3) {")
Text(" Text(\"My item!\")")
Text(" }")
Text("}")
}
Text("")
List(ordered = true) {
repeat(3) {
Text("My item!")
}
}
Text("")
H3("Download")
Text("")
Text("Will be published to MavenCentral soon.")
}
println(readme)
}
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ dependencyResolutionManagement {
include(
":markdown-runtime",
":markdown-ui",
":sample",
)

0 comments on commit 06592b3

Please sign in to comment.