Android Library To Render Markdown Strings Inside Jetpack Compose Applications
Built With Native Jetpack Compose Composables
- Jetpack Compose : 1.3.1
- Image Loading Library (Coil) : 2.1.0
- Minumum Sdk Version : 24
- Target Sdk Version : 32
- Jetpack Compose UI : 1.1.1
allprojects {
repositories {
mavenCentral()
}
}
dependencies {
implementation "com.yazantarifi:markdown-compose:1.0.4"
}
- Basic Implementation
MarkdownViewComposable(
modifier = Modifier.fillMaxWidth().padding(10.dp),
content = content,
config = MarkdownConfig(
isLinksClickable = true,
isImagesClickable = true,
isScrollEnabled = false
)
) { link, type ->
// Callback on Click on Images, Links To Redirect to Image Viewer or WebView Screen
}
- Color Control Example
MarkdownViewComposable(
modifier = Modifier.fillMaxWidth().padding(10.dp),
content = content,
config = MarkdownConfig(
isLinksClickable = true,
isImagesClickable = true,
isScrollEnabled = false,
colors = HashMap<String, Color>().apply {
this[MarkdownConfig.CHECKBOX_COLOR] = Color.Black
this[MarkdownConfig.LINKS_COLOR] = Color.Blue
this[MarkdownConfig.TEXT_COLOR] = Color.Gray
this[MarkdownConfig.HASH_TEXT_COLOR] = Color.Black
this[MarkdownConfig.CODE_BACKGROUND_COLOR] = Color.Gray
this[MarkdownConfig.CODE_BLOCK_TEXT_COLOR] = Color.White
}
)
) { link, type ->
when (type) {
MarkdownConfig.IMAGE_TYPE -> {} // Image Clicked
MarkdownConfig.LINK_TYPE -> {} // Link Clicked
}
}
Attribute | Description |
---|---|
isLinksClickable | Allow Links in View to be Clickable |
isImagesClickable | Allow Images in View to be Clickable |
isScrollEnabled | Allow Md View To be Scrollable Inside itself (False if it's already inside Scroll View or LazyColumn) |
colors | Pass Colors Based on Your Application Theme |
MarkdownConfig.CHECKBOX_COLOR | The Color of Checkboxes When Checkbox is Checked |
MarkdownConfig.LINKS_COLOR | The Color of Links |
MarkdownConfig.TEXT_COLOR | Normal Text Color |
MarkdownConfig.HASH_TEXT_COLOR | Hashes Text Color (#, ##, ###, ####) |
MarkdownConfig.CODE_BACKGROUND_COLOR | Background of Code Block |
MarkdownConfig.CODE_BLOCK_TEXT_COLOR | Text Color Inside Code Block |
Images 1 | Images 2 | Images 3 |
---|---|---|
- Hash Texts
- Code Blocks
- Text
- Checkbox
- Images
- Shilds
- Bold Text
- Italic Text
- Links
- Space
gradle build
gradle library:publishReleasePublicationToSonatypeRepository
Copyright (C) 2022 Markdown Compose is An Open Source Library (Licensed under the Apache License, Version 2.0)