Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load markdown images with Coil3 #327

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Load markdown images with Coil3 #327

wants to merge 1 commit into from

Conversation

obask
Copy link
Collaborator

@obask obask commented Mar 22, 2024

No description provided.

@obask obask marked this pull request as draft March 22, 2024 06:42
@rock3r rock3r added the markdown This issue impacts the Markdown rendering subsystem label Jul 4, 2024
@rock3r rock3r linked an issue Sep 6, 2024 that may be closed by this pull request
@obask obask force-pushed the feature-image-loading branch from 98c42bc to 806f009 Compare November 10, 2024 21:56
@obask obask changed the title Coil3 isnt quite working Load markdown images with Coil3 Nov 11, 2024
@obask obask force-pushed the feature-image-loading branch 3 times, most recently from 57f2c0a to 38797b6 Compare November 18, 2024 11:27
@obask obask requested a review from rock3r November 18, 2024 11:29
@obask obask force-pushed the feature-image-loading branch from 38797b6 to 78a3bc9 Compare November 18, 2024 13:08
markdown/core/build.gradle.kts Outdated Show resolved Hide resolved
Comment on lines +143 to +150
/**
* This method sets up an image loader with a memory cache but disables the disk cache. Disabling the disk cache is
* necessary because Coil crashes when attempting to use the file system cache with IDEA platform.
*
* Otherwise Coil3 will throw java.lang.NoSuchMethodError: kotlinx.coroutines.CoroutineDispatcher.limitedParallelism
*/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you filed a Coil bug for this? Or is there a workaround, like moving the init to the bridge and standalone modules, handling things differently in each case? For what you write, disk caching should work fine in standalone as-is, and may require a different approach for the bridge, where we provide a custom implementation that works in IJP.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thought is that this issue is specific to our way of loading dependencies in ide-plugin(or kotlin versions). I think we can add a todo here to delete this invocation once we move Jewel to the platform, since this will likely streamline all dependencies.
This workaround is not needed for standalone mode.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This workaround is not needed for standalone mode.

So it should only be done in the bridge version, and indeed we need an issue to track checking this again when we move to the IJP

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Markdown is invoked directly from the example code. Do you know how to add it to the bridge only?
Additionally, if we change IDE vs Standalone behaviour, it would be much more difficult to figure out if something is wrong in one but works fine in another.

model =
ImageRequest.Builder(LocalPlatformContext.current).data(image.source).size(Size.ORIGINAL).build(),
contentDescription = image.title,
// TODO: figure out what to use instead of *.sp
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you not using dp?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InlineTextContent only accepts size in as a TextUnit which is either em or sp. I'll change logic to use more advanced conversion.
I polished this logic a bit and added a comment, but I haven't figured out how to make Coil scale up images to the size of placeholder.

@obask obask force-pushed the feature-image-loading branch from 78a3bc9 to f076393 Compare November 20, 2024 15:15
@obask obask requested a review from rock3r November 20, 2024 15:21
)
}
) {
AsyncImage(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW you need to make sure Ktor is initialised correctly (e.g., in the IDE it needs to respect the IDE proxy settings).

As a starting point, you can do something like this: https://gist.github.com/rock3r/6f633cb0e5b73625cc6ec0570896ff85

Of course this needs more work than just copy pasting it, but it should point you in the right direction

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as we discussed offline, it would be easier to do after the intellij-community move

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be warned you'll have to recreate the branch and PR on the IJ repo. You'll also need to manage both Gradle and JPS builds in parallel

@rock3r
Copy link
Collaborator

rock3r commented Nov 24, 2024

It supports every image as inline
@obask obask force-pushed the feature-image-loading branch from f076393 to 46f29ca Compare November 25, 2024 13:10
@obask
Copy link
Collaborator Author

obask commented Nov 25, 2024

@obask for inline images, you can probably take inspiration from https://github.com/halilozercan/compose-richtext/blob/main/richtext-ui/src/commonMain/kotlin/com/halilibo/richtext/ui/string/InlineContent.kt

I think it does the same .toSp() conversion as a previous version of the code. I also updated the way we handle state and deleted a special case for block images.

@obask
Copy link
Collaborator Author

obask commented Nov 25, 2024

And I fixed images scaling, BTW. It shows them the same way as other markdown editors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
markdown This issue impacts the Markdown rendering subsystem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Load images in Markdown
3 participants