halilozercan / compose-richtext

A collection of Compose libraries for advanced text formatting and alternative display types.
https://halilibo.com/compose-richtext
Apache License 2.0
750 stars 59 forks source link

Option to use parsed Markdown #123

Closed tananaev closed 4 months ago

tananaev commented 10 months ago

Currently the library parses markdown internally, but there are several issues with it:

This PR adds an overload for Markdown composable that takes Commonmark Node object.

One drawback is that we need to expose Commonmark as an API dependency because public API now uses it, but feel like it should be ok considering that the module is called richtext-commonmark.

halilozercan commented 10 months ago

During the initial implementation of Markdown composable, we've had a similar discussion about exposing an alternative API where commonmark would be just another pluggable parser to a common Markdown Tree that we can define for ourselves. This way anyone could use their own parser or parser+translation combo to create their Markdown composable. Unfortunately, we never got the time to try this and the development stagnated heavily.

Would you be willing to introduce something like that? I know it's a way larger project in scope compared to this solution. Although the module itself is named richtext-commonmark, I still wouldn't feel easy about exposing that relation on the API surface.

tananaev commented 10 months ago

Can you please clarify what the API would look like. Do you mean passing a parser function directly into composable? Wouldn't that require commonmark dependency as well? Also passing a parser wouldn't solve some of the problems related to asynchronous calls in the UI code.

One option I can think of is to make own data models that map to commonmark internally. That way we don't need to expose commonmark externally. Basically exposing AstNode and other classes.

tananaev commented 10 months ago

@halilozercan any thoughts? I'm happy to modify the code, but need some clarification.

tananaev commented 9 months ago

@halilozercan are we able to move forward with something? Any guidance on what you want to see as the API?

dimitriz09 commented 5 months ago

Very interesting point of view. I personally think having a custom parser is not that important, but it's because the solution as it is now fits my needs. The asynchronous loading is really a pain in lists though.

dimitriz09 commented 5 months ago

@halilozercan Could you consider synchronized composition so we can use markdown in lazylists more efficiently ? Regards, Dimitri

halilozercan commented 5 months ago

I'm sorry for abandoning this issue and the discussion.

Here is what I had in mind;

The only difficult element in this path is figuring out the API for ASTNode. A couple of options off the top of my head

halilozercan commented 4 months ago

129 adds a similar capability without exposing the commonmark dependency.