Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/build-verification.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Build Verification

on:
push:
branches: [main]
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
workflow_dispatch:
Expand Down
43 changes: 32 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![Maven Central](https://img.shields.io/maven-central/v/com.sumup.markdown/annotatedstring-generator)](https://central.sonatype.com/artifact/com.sumup.markdown/annotatedstring-generator)


A lightweight Android library to convert Markdown text into a Jetpack Compose `AnnotatedString`. This allows you to easily render formatted text from Markdown in your Compose UI.
A lightweight Android library to convert Markdown text into a Jetpack Compose `AnnotatedString`. Use `com.sumup.markdown:annotatedstring-generator` to produce one `AnnotatedString` for a Compose `Text` on Android (`minSdk` 24).

This library is built on top of [JetBrains intellij-markdown](https://github.com/JetBrains/markdown), a multiplatform Markdown processor written in Kotlin.

Expand All @@ -20,13 +20,22 @@ This library supports common Markdown syntax, including:
* Horizontal rules
* Images (rendered as text placeholder)

## Requirements

* Android `minSdk` 24
* Jetpack Compose. Compose Foundation is brought in by this library.

## When to use this

Use this library when Markdown should become one styled string inside a Compose `Text`. The parser is CommonMark through [JetBrains intellij-markdown](https://github.com/JetBrains/markdown). Links are a `"URL"` string annotation. Images are text placeholders. A `TextView`/`Spannable` library, or a renderer that emits a column of Compose nodes, fits a different layout.

## Installation

Add the dependency to your module's `build.gradle.kts`:
Add the dependency to your module's `build.gradle.kts`. The Maven Central badge above shows the latest published version. This snippet uses `0.1.1`.

```kotlin
dependencies {
implementation("com.sumup.markdown:annotatedstring-generator:0.1.0")
implementation("com.sumup.markdown:annotatedstring-generator:0.1.1")
}
```

Expand All @@ -35,19 +44,15 @@ dependencies {

```groovy
dependencies {
implementation 'com.sumup.markdown:annotatedstring-generator:0.1.0'
implementation 'com.sumup.markdown:annotatedstring-generator:0.1.1'
}
```
</details>

<!-- For snapshot versions, add the Maven Central snapshots repository in your settings.gradle.kts:
maven("https://central.sonatype.com/repository/maven-snapshots/")
and use version "0.1.0-SNAPSHOT" instead. -->

<details>
<summary>Snapshot versions</summary>

To use a **snapshot** version (e.g., `0.1.0-SNAPSHOT`), add the Maven Central snapshots repository in your `settings.gradle.kts`:
Stable releases are published to Maven Central. To try an unpublished snapshot (for example `0.1.2-SNAPSHOT`), add the Maven Central snapshots repository in your `settings.gradle.kts`:

```kotlin
dependencyResolutionManagement {
Expand All @@ -63,16 +68,24 @@ Then use the snapshot version in your dependency:

```kotlin
dependencies {
implementation("com.sumup.markdown:annotatedstring-generator:0.1.0-SNAPSHOT")
implementation("com.sumup.markdown:annotatedstring-generator:0.1.2-SNAPSHOT")
}
```
</details>

## Usage

Imports:

```kotlin
import com.sumup.markdown.annotatedstring.AnnotatedStringGenerator
import com.sumup.markdown.annotatedstring.CommonMarkFlavourDescriptor
import org.intellij.markdown.parser.MarkdownParser
```

### Basic Usage

Parse your markdown and generate an `AnnotatedString` in three lines:
Parse your markdown and generate an `AnnotatedString`:

```kotlin
val markdown = "Hello **world**! This is *italic* and `code`."
Expand Down Expand Up @@ -131,6 +144,8 @@ fun ClickableMarkdownText(markdown: String, modifier: Modifier = Modifier) {
}
```

The [`sample`](sample) module is a small Compose playground for the same API.

## Building from Source

To build the library from source, clone the repository and run the following command:
Expand All @@ -153,6 +168,12 @@ To run the Paparazzi snapshot tests:
./gradlew :annotatedstring-generator:verifyPaparazziDebug
```

## Project

* [Changelog](CHANGELOG.md)
* [Contributing](CONTRIBUTING.md)
* [Security](SECURITY.md)

## License

```
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ GROUP=com.sumup.markdown
VERSION_NAME=0.1.1
POM_ARTIFACT_ID=annotatedstring-generator
POM_NAME=Markdown to AnnotatedString Generator
POM_DESCRIPTION=Android library to convert Markdown into Compose AnnotatedString
POM_DESCRIPTION=A lightweight Android library to convert Markdown text into a Jetpack Compose AnnotatedString. Use com.sumup.markdown:annotatedstring-generator to produce one AnnotatedString for a Compose Text on Android (minSdk 24).
POM_URL=https://github.com/sumup-oss/markdown-annotatedstring

# Provide these in CI as ORG_GRADLE_PROJECT_* environment variables.
Expand Down
19 changes: 19 additions & 0 deletions llms.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Markdown to AnnotatedString Generator

> Android library that converts Markdown into one Jetpack Compose AnnotatedString for a Text.

Use this when Markdown should become one styled string inside a Compose `Text`. The parser is CommonMark through JetBrains intellij-markdown. Links are a `"URL"` string annotation. Images are text placeholders. A `TextView`/`Spannable` library, or a renderer that emits a column of Compose nodes, fits a different layout.

Android `minSdk` 24. Maven coordinates: `com.sumup.markdown:annotatedstring-generator:0.1.1`.

```kotlin
val markdown = "Hello **world**! This is *italic* and `code`."
val flavour = CommonMarkFlavourDescriptor()
val parser = MarkdownParser(flavour)
val root = parser.buildMarkdownTreeFromString(markdown)
val annotatedString = AnnotatedStringGenerator(markdown, root, flavour).generateAnnotatedString()
```

## Docs

- [README](https://github.com/sumup-oss/markdown-annotatedstring#readme): install snippets, Compose `Text` sample, and link-click handling
Loading