$ show halilozercan/compose-richtext
This repository is a Kotlin Multiplatform (KMP) library collection designed for rendering rich text and Markdown within Compose applications on Android and Desktop. It consists of several modular artifacts: `richtext-ui` (core UI composables), `richtext-markdown` (AST-based rendering), `richtext-commonmark` (CommonMark parser integration), and theme-specific wrappers (`richtext-ui-material`, `richtext-ui-material3`). The architecture relies on a custom Abstract Syntax Tree (AST) representation of Markdown content, which is traversed recursively to emit Compose composables. While the codebase demonstrates strong engineering practices, particularly in handling deep nesting and large documents, the README explicitly warns that the project is experimental, lacks tests, and has an unclear roadmap. This makes it suitable for prototyping or internal tools but potentially risky for production-critical applications without significant validation.
The LLM identified 3 files worth highlighting for reuse:
Implements an iterative tree traversal algorithm to convert CommonMark nodes into the library's internal AST. This is a critical engineering decision that prevents StackOverflowError on deeply nested or extremely long Markdown documents, a common pitfall in recursive parsers. The code uses an explicit stack (`ArrayDeque<ConvertWorkItem>`) to manage the conversion state, ensuring robustness for large inputs.
Defines a custom `RichTextString` class that extends `AnnotatedString` with a builder pattern for formatting directives (bold, italic, links, inline content). It manages format objects separately from the string content, allowing for efficient style resolution and inline content handling. This abstraction decouples the text content from the rendering logic, making it reusable across different text rendering contexts.
Contains the core rendering logic for the Markdown AST. It defines the `AstBlockNodeComposer` interface, which allows consumers to intercept and customize the rendering of specific block types (e.g., images, tables) without modifying the core library. The `RecursiveRenderMarkdownAst` function handles the traversal and composition of nodes, demonstrating a clean separation between data structure (AST) and presentation (Composables).