How mikepenz/multiplatform-markdown-renderer works
Main Components
• Core Library Module:
– The central “multiplatform-markdown-renderer” provides common markdown processing (parsing using JetBrains’ library) and rendering logic using Compose.
– It exposes the main Markdown composable API and supports various customizations (styles, animations, extended spans, etc.).
• Feature/Extension Modules:
– Modules for theming (m2 and m3): Provide Material 2 and Material 3 defaults.
– Image Transformer Modules (coil2 and coil3): Offer image-loading strategies using different versions of Coil.
– Code Syntax Highlighting Module (code): Integrates with an external highlighter (Highlights) for rendering code blocks.
• API Modules:
– Each module includes separate API definitions (e.g., the “api” subdirectories for android, jvm, and klib) to specify interfaces and expected behaviors.
• Platform-Specific Implementation Modules:
– Each multiplatform module contains directories for platform-specific code (androidMain, jvmMain, iosMain, etc.) to handle platform-specific rendering concerns.
• Sample Applications:
– The “sample” folder shows real-life integration for Android, Desktop, iOS, Web, and shared modules to demonstrate how to consume the library.
Detail the Relationships and Interactions
• The Core Module interacts directly with all other modules:
– Common business logic and markdown parsing/rendering lies at the center.
– Feature modules (m2/m3, coil2/coil3, code) extend or specialize that core via additional rendering components (like custom Markdown components).
• Platform-Specific API Implementations:
– Each platform-specific directory (androidMain, jvmMain, iosMain, etc.) implements the necessary glue-code that adapts the common logic to that platform.
• Dependency Injection & Customizability:
• Gradle and CI Integration:
– The project uses Gradle (with build.gradle.kts scripts, gradle.properties, and the Gradle wrapper) to build, package, and manage dependencies.
– CI workflows (under .github/workflows) ensure continuous integration and testing.
Architectural Patterns and Design Principles
• Modularity:
– The project is split into separate modules for core functionality, feature-specific enhancements, and platform adaptations.
• Separation of Concerns:
– The rendering logic (Markdown composable), API definitions, and platform-specific implementations are organized in distinct directories.
• Extensibility by Design:
– By allowing custom components, annotators, and configurable image transformers and code highlighters, the system adheres to the Open/Closed Principle.
• Gradle/Multi-platform Build Pattern:
– Leveraging Kotlin multiplatform’s source set segregation (commonMain and platform-specific directories), the project cleanly isolates shared logic from platform-specific concerns.