Skip to content

Commit

Permalink
Version bump 1.5.12
Browse files Browse the repository at this point in the history
This change includes bunch of misc tech debt cleaning.

- Use Compose Multiplatform dependencies instead of Google's Compose artifacts
- Removed Previews from richtext-ui.
- Renamed CodeBlock platform files.
- Kotlin updated to 1.9.22
- Compose compiler update to 1.5.8
- Changed MarkdownSample to use CommonmarkAstNodeParser and do synchronous Markdown rendering.
  • Loading branch information
halilozercan committed Feb 9, 2024
1 parent db4de67 commit d9f031c
Show file tree
Hide file tree
Showing 22 changed files with 73 additions and 356 deletions.
9 changes: 5 additions & 4 deletions android-sample/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id("com.android.application")
kotlin("android")
id("org.jetbrains.compose") version Compose.desktopVersion
}

android {
Expand Down Expand Up @@ -36,8 +37,8 @@ dependencies {
implementation(project(":slideshow"))
implementation(AndroidX.appcompat)
implementation(Compose.activity)
implementation(Compose.foundation)
implementation(Compose.icons)
implementation(Compose.material)
implementation(Compose.tooling)
implementation(compose.foundation)
implementation(compose.materialIconsExtended)
implementation(compose.material)
implementation(compose.uiTooling)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import android.widget.Toast
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
Expand All @@ -30,8 +32,9 @@ import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.em
import com.halilibo.richtext.commonmark.Markdown
import com.halilibo.richtext.commonmark.CommonmarkAstNodeParser
import com.halilibo.richtext.commonmark.MarkdownParseOptions
import com.halilibo.richtext.markdown.BasicMarkdown
import com.halilibo.richtext.ui.RichTextStyle
import com.halilibo.richtext.ui.material.RichText
import com.halilibo.richtext.ui.resolveDefaults
Expand All @@ -41,6 +44,7 @@ import com.halilibo.richtext.ui.resolveDefaults
MarkdownSample()
}

@OptIn(ExperimentalLayoutApi::class)
@Composable fun MarkdownSample() {
var richTextStyle by remember { mutableStateOf(RichTextStyle().resolveDefaults()) }
var isDarkModeEnabled by remember { mutableStateOf(false) }
Expand Down Expand Up @@ -70,29 +74,29 @@ import com.halilibo.richtext.ui.resolveDefaults
// Config
Card(elevation = 4.dp) {
Column {
CheckboxPreference(
onClick = {
isDarkModeEnabled = !isDarkModeEnabled
},
checked = isDarkModeEnabled,
label = "Dark Mode"
)

CheckboxPreference(
onClick = {
isWordWrapEnabled = !isWordWrapEnabled
},
checked = isWordWrapEnabled,
label = "Word Wrap"
)

CheckboxPreference(
onClick = {
isAutolinkEnabled = !isAutolinkEnabled
},
checked = isAutolinkEnabled,
label = "Autolink"
)
FlowRow {
CheckboxPreference(
onClick = {
isDarkModeEnabled = !isDarkModeEnabled
},
checked = isDarkModeEnabled,
label = "Dark Mode"
)
CheckboxPreference(
onClick = {
isWordWrapEnabled = !isWordWrapEnabled
},
checked = isWordWrapEnabled,
label = "Word Wrap"
)
CheckboxPreference(
onClick = {
isAutolinkEnabled = !isAutolinkEnabled
},
checked = isAutolinkEnabled,
label = "Autolink"
)
}

RichTextStyleConfig(
richTextStyle = richTextStyle,
Expand All @@ -104,13 +108,20 @@ import com.halilibo.richtext.ui.resolveDefaults
SelectionContainer {
Column(Modifier.verticalScroll(rememberScrollState())) {
ProvideTextStyle(TextStyle(lineHeight = 1.3.em)) {
val parser = remember(markdownParseOptions) {
CommonmarkAstNodeParser(markdownParseOptions)
}

val astNode = remember(parser) {
parser.parse(sampleMarkdown)
}

RichText(
style = richTextStyle,
modifier = Modifier.padding(8.dp),
) {
Markdown(
content = sampleMarkdown,
markdownParseOptions = markdownParseOptions,
BasicMarkdown(
astNode = astNode,
onLinkClicked = {
Toast.makeText(context, it, Toast.LENGTH_SHORT).show()
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ subprojects {
allWarningsAsErrors = true
}

freeCompilerArgs = listOf("-opt-in=kotlin.RequiresOptIn")
freeCompilerArgs = listOf("-opt-in=kotlin.RequiresOptIn", "-Xexpect-actual-classes")
}
}

Expand Down
15 changes: 4 additions & 11 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object Network {

object Kotlin {
// keep in sync with buildSrc/build.gradle.kts
val version = "1.9.20"
val version = "1.9.22"
val binaryCompatibilityValidatorPlugin = "org.jetbrains.kotlinx:binary-compatibility-validator:0.9.0"
val gradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$version"

Expand All @@ -31,19 +31,12 @@ val ktlint = "org.jlleitschuh.gradle:ktlint-gradle:10.0.0"

object Compose {
val version = "1.5.4"
val compilerVersion = "1.5.4"
val desktopVersion = "1.5.11"
val compilerVersion = "1.5.8"
val desktopVersion = "1.5.12"
val activity = "androidx.activity:activity-compose:1.7.2"
val foundation = "androidx.compose.foundation:foundation:$version"
val material = "androidx.compose.material:material:$version"
val material3 = "androidx.compose.material3:material3:1.0.1"
val icons = "androidx.compose.material:material-icons-extended:$version"
val test = "androidx.ui:ui-test:$version"
val tooling = "androidx.compose.ui:ui-tooling:$version"
val toolingData = "androidx.compose.ui:ui-tooling-data:$version"
val desktopPreview = "org.jetbrains.compose.ui:ui-tooling-preview-desktop:$desktopVersion"
val multiplatformUiUtil = "org.jetbrains.compose.ui:ui-util:$desktopVersion"
val coil = "io.coil-kt:coil-compose:2.4.0"
val coil = "io.coil-kt:coil-compose:2.5.0"
}

object Commonmark {
Expand Down
2 changes: 1 addition & 1 deletion docs/richtext-commonmark.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ String to an `AstNode` that represents the Markdown tree.
)
// ...

RichTextScope.Markdown(astNode)
RichTextScope.BasicMarkdown(astNode)
```

## Rendering
Expand Down
16 changes: 7 additions & 9 deletions docs/richtext-markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
[![Android Library](https://img.shields.io/badge/Platform-Android-green.svg?style=for-the-badge)](https://developer.android.com/studio/build/dependencies)
[![JVM Library](https://img.shields.io/badge/Platform-JVM-red.svg?style=for-the-badge)](https://kotlinlang.org/docs/mpp-intro.html)

Library for rendering Markdown tree defined as an `AstNode`.
Library for rendering Markdown tree that is defined as an `AstNode`. This module would be useless
for someone who is looking to just render a Markdown string. Please take a look to
`richtext-commonmark` for such features. `richtext-markdown` behaves as sort of a building block.
You can create your own parser or use 3rd party ones that converts any Markdown string to an
`AstNode` tree.

## Gradle

Expand All @@ -13,13 +17,6 @@ dependencies {
}
```

## Usage

`richtext-markdown` module renders a given Markdown Abstract Syntax Tree. It accepts a root
`AstNode`. However, this library does not include a parser to convert a regular Markdown String into
an `AstNode`. Please refer to `richtext-commonmark` for a sample implementation or a quick way to
render Markdown.

## Rendering

The simplest way to render markdown is just pass an `AstNode` to the [`Markdown`](../api/richtext-commonmark/com.halilibo.richtext.markdown/-markdown.html)
Expand All @@ -29,6 +26,7 @@ composable under RichText scope:
RichText(
modifier = Modifier.padding(16.dp)
) {
// requires richtext-commonmark module.
val parser = remember(options) { CommonmarkAstNodeParser(options) }
val astNode = remember(parser) {
parser.parse(
Expand All @@ -49,6 +47,6 @@ RichText(
""".trimIndent()
)
}
Markdown(astNode)
BasicMarkdown(astNode)
}
~~~
2 changes: 1 addition & 1 deletion docs/richtext-ui-material3.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Richtext UI Material
# Richtext UI Material 3

[![Android Library](https://img.shields.io/badge/Platform-Android-green.svg?style=for-the-badge)](https://developer.android.com/studio/build/dependencies)
[![JVM Library](https://img.shields.io/badge/Platform-JVM-red.svg?style=for-the-badge)](https://kotlinlang.org/docs/mpp-intro.html)
Expand Down
7 changes: 4 additions & 3 deletions printing/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
plugins {
id("richtext-android-library")
id("org.jetbrains.dokka")
id("org.jetbrains.compose") version Compose.desktopVersion
}

android {
namespace = "com.zachklipp.richtext.ui.printing"
}

dependencies {
implementation(Compose.foundation)
implementation(Compose.tooling)
implementation(compose.foundation)
implementation(compose.uiTooling)
// For slot table analysis.
implementation(Compose.toolingData)
implementation(Compose.activity)

// TODO Migrate off this.
implementation(Compose.material)
implementation(compose.material)
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class.java).all {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.produceState
import androidx.compose.runtime.remember
import com.halilibo.richtext.markdown.Markdown
import com.halilibo.richtext.markdown.BasicMarkdown
import com.halilibo.richtext.commonmark.MarkdownParseOptions.Companion
import com.halilibo.richtext.markdown.node.AstNode
import com.halilibo.richtext.ui.RichTextScope
Expand Down Expand Up @@ -35,7 +35,7 @@ public fun RichTextScope.Markdown(
}

astRootNode?.let {
Markdown(astNode = it, onLinkClicked = onLinkClicked)
BasicMarkdown(astNode = it, onLinkClicked = onLinkClicked)
}
}

Expand Down
4 changes: 2 additions & 2 deletions richtext-markdown/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
POM_NAME=Compose Richtext Commonmark
POM_DESCRIPTION=A library for rendering markdown in Compose using the Commonmark library.
POM_NAME=Compose Richtext Markdown
POM_DESCRIPTION=A library for rendering markdown represented as an AST in Compose.
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ import com.halilibo.richtext.ui.string.richTextString

/**
* A composable that renders Markdown content pointed by [astNode] into this [RichTextScope].
* Designed to be a building block that should be wrapped with a specific parser.
*
* @param astNode Root node of Markdown tree. This can be obtained via a parser.
* @param onLinkClicked A function to invoke when a link is clicked from rendered content.
*/
@Composable
public fun RichTextScope.Markdown(
public fun RichTextScope.BasicMarkdown(
astNode: AstNode,
onLinkClicked: ((String) -> Unit)? = null
) {
Expand Down Expand Up @@ -186,7 +187,7 @@ internal fun RichTextScope.visitChildren(node: AstNode?) {
}

/**
* An internal ambient to pass through OnLinkClicked function from root [Markdown] composable
* An internal ambient to pass through OnLinkClicked function from root [BasicMarkdown] composable
* to children that render links. Although being explicit is preferred, recursive calls to
* [visitChildren] increases verbosity with each extra argument.
*/
Expand Down
4 changes: 0 additions & 4 deletions richtext-ui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ kotlin {
}
val jvmMain by getting {
kotlin.srcDir("src/commonJvmAndroid/kotlin")
dependencies {
// requires installing https://plugins.jetbrains.com/plugin/16541-compose-multiplatform-ide-support
implementation(Compose.desktopPreview)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@file:JvmName("CodeBlockAndroid")
package com.halilibo.richtext.ui

import androidx.compose.foundation.horizontalScroll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ import androidx.compose.foundation.gestures.GestureCancellationException
import androidx.compose.foundation.gestures.PressGestureScope
import androidx.compose.foundation.gestures.awaitEachGesture
import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.gestures.forEachGesture
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.input.pointer.AwaitPointerEventScope
import androidx.compose.ui.input.pointer.PointerEventTimeoutCancellationException
import androidx.compose.ui.input.pointer.PointerEventPass
import androidx.compose.ui.input.pointer.PointerEventTimeoutCancellationException
import androidx.compose.ui.input.pointer.PointerInputChange
import androidx.compose.ui.input.pointer.PointerInputScope
import androidx.compose.ui.input.pointer.changedToUp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@file:JvmName("CodeBlockJvm")
package com.halilibo.richtext.ui

import androidx.compose.foundation.HorizontalScrollbar
Expand Down

This file was deleted.

Loading

0 comments on commit d9f031c

Please sign in to comment.