Skip to content

Commit

Permalink
Coil3 isnt quite working
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg Baskakov committed Mar 22, 2024
1 parent 93d7e26 commit 98c42bc
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 10 deletions.
2 changes: 2 additions & 0 deletions markdown/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Additional supported Markdown, via extensions:

* Alerts ([GitHub Flavored Markdown][alerts-specs]) — see [`extension-gfm-alerts`](extension-gfm-alerts)

Im**agetime, and no guarantees are made for binary and source compatibility. It might also have bugs and missing features. ![here is an image](https://hellorse.fr/images/p/media/image/products/product_76409_2b3beddbf246765581c5e91a9fd6.webp?p=product_thumbnail&type=product) And ot**her stuff time, and no guarantees are made for binary and source compatibility. It might also have bugs and missing features. time, and no guarantees are made for binary and source compatibility. It might also have bugs and missing features.

[alerts-specs]: https://github.com/orgs/community/discussions/16925

On the roadmap, but not currently supported — in no particular order:
Expand Down
4 changes: 4 additions & 0 deletions markdown/core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ plugins {
dependencies {
compileOnly(projects.ui)
api(libs.commonmark.core)
implementation("io.coil-kt.coil3:coil-compose:3.0.0-alpha06")
// Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Module with the Main dispatcher is missing. Add dependency providing the Main dispatcher, e.g. 'kotlinx-coroutines-android' and ensure it has the same version as 'kotlinx-coroutines-core'
// https://github.com/coil-kt/coil/issues/842#issuecomment-1975115060
runtimeOnly("org.jetbrains.kotlinx:kotlinx-coroutines-swing:1.8.1-Beta")

testImplementation(compose.desktop.uiTestJUnit4)
testImplementation(projects.ui)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,17 @@ public class MarkdownProcessor(private val extensions: List<MarkdownProcessorExt
when (this) {
is BlockQuote -> toMarkdownBlockQuote()
is Heading -> toMarkdownHeadingOrNull()
is Paragraph -> toMarkdownParagraphOrNull()
is Paragraph -> {
val child = firstChild
if (child is Image && child === lastChild) {
// only render standalone images as blocks
child.toMarkdownImageOrNull()
} else {
toMarkdownParagraphOrNull()
}
}
is FencedCodeBlock -> toMarkdownCodeBlockOrNull()
is IndentedCodeBlock -> toMarkdownCodeBlockOrNull()
is Image -> toMarkdownImageOrNull()
is BulletList -> toMarkdownListOrNull()
is OrderedList -> toMarkdownListOrNull()
is ThematicBreak -> MarkdownBlock.ThematicBreak
Expand Down Expand Up @@ -144,7 +151,7 @@ public class MarkdownProcessor(private val extensions: List<MarkdownProcessorExt
private fun Image.toMarkdownImageOrNull(): MarkdownBlock.Image? {
if (destination.isBlank()) return null

return MarkdownBlock.Image(destination.trim(), title.trim())
return MarkdownBlock.Image(destination.trim(), (title?:"").trim())
}

private fun BulletList.toMarkdownListOrNull(): UnorderedList? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ import org.jetbrains.jewel.markdown.extensions.MarkdownRendererExtension
import org.jetbrains.jewel.ui.Orientation.Horizontal
import org.jetbrains.jewel.ui.component.Divider
import org.jetbrains.jewel.ui.component.Text
import coil3.ImageLoader
import coil3.PlatformContext
import coil3.Uri
import coil3.compose.AsyncImage
import coil3.disk.DiskCache
import coil3.memory.MemoryCache
import coil3.request.crossfade
import coil3.util.DebugLogger


@ExperimentalJewelApi
public open class DefaultMarkdownBlockRenderer(
Expand Down Expand Up @@ -416,14 +425,39 @@ public open class DefaultMarkdownBlockRenderer(

@Composable
override fun render(block: Image, styling: MarkdownStyling.Image) {
// TODO implement image rendering support (will require image loading)
Text(
"⚠️ Images are not supported yet",
Modifier.border(1.dp, Color.Red)
.padding(horizontal = 8.dp, vertical = 4.dp)
.pointerHoverIcon(PointerIcon.Default, overrideDescendants = true),
color = Color.Red,
// val loader = ImageLoader.Builder(context)
// .memoryCache {
// MemoryCache.Builder()
// // Set the max size to 25% of the app's available memory.
// .maxSizePercent(context, percent = 0.25)
// .build()
// }
// .diskCache {
// newDiskCache()
// }
// // Show a short crossfade when loading images asynchronously.
// .crossfade(true)
// // Enable logging if this is a debug build.
// .apply {
// if (debug) {
// logger(DebugLogger())
// }
// }
// .build()

AsyncImage(
model = block.url,
contentDescription = block.altString,
)

// TODO implement image rendering support (will require image loading)
// Text(
// "⚠️ Images are not supported yet",
// Modifier.border(1.dp, Color.Red)
// .padding(horizontal = 8.dp, vertical = 4.dp)
// .pointerHoverIcon(PointerIcon.Default, overrideDescendants = true),
// color = Color.Red,
// )
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ internal val JewelReadme = """
<img alt="Jewel logo" src="art/jewel-logo.svg" width="20%"/>
![Some IMG](https://hellorse.fr/images/p/media/image/products/product_76409_2b3beddbf246765581c5e91a9fd6.webp?p=product_thumbnail&type=product)
Jewel aims at recreating the IntelliJ Platform's _New UI_ Swing Look and Feel in Compose for Desktop, providing a
desktop-optimized theme and set of components.
Expand Down

0 comments on commit 98c42bc

Please sign in to comment.