feat: add synchronous parseMarkdown returning a parsed State#591
Merged
mikepenz merged 1 commit intoJun 22, 2026
Merged
Conversation
Adds a public top-level parseMarkdown(content, lookupLinks, flavour, parser, referenceLinkHandler): State alongside parseMarkdownFlow. It parses on the calling thread and returns the final immutable State directly (State.Success or State.Error), without exposing any mutable Flow/StateFlow surface. Useful to pre-parse content before the UI is shown and pass the parsed state into the Markdown composable. Reuses the existing Input / MarkdownStateImpl / parseBlocking path, so it is purely additive. Adds commonTest coverage and documents the function in the README. Closes mikepenz#587
3 tasks
mikepenz
approved these changes
Jun 22, 2026
Contributor
Author
|
Thank you @mikepenz. A synchronous parseMarkdown that returns a parsed State is a handy addition for callers that don't want the async path. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a public top-level
parseMarkdown(content, lookupLinks, flavour, parser, referenceLinkHandler): StatetoMarkdownState.kt, sitting alongside the existingparseMarkdownFlow(...)and mirroring its parameter list and defaults. It parses on the calling thread and returns the final, immutableStatedirectly (State.Successon success, orState.Erroron failure).Internally it builds the same
InputandMarkdownStateImpland calls the already-presentparseBlocking(), so the change is purely additive and reuses every existing code path (input construction, parsing, link lookup).Motivation: today the only non-composable parse API is
parseMarkdownFlow(), which forces callers through mutable Flow/StateFlow machinery to obtain a result. There was no way to synchronously get aState.Successto hand to theMarkdowncomposable.parseMarkdownlets you pre-parse content before the UI is shown and pass the already-parsed, immutableStatestraight intoMarkdown(state), with no mutable surface exposed to the caller.Note: parsing happens on the calling thread; for large documents callers should invoke off the main thread.
Fixes #587
Type of change
How Has This Been Tested?
Added
ParseMarkdownTestincommonTestand ran it on the JVM target../gradlew :multiplatform-markdown-renderer:jvmTest --tests "com.mikepenz.markdown.model.ParseMarkdownTest"passes (4/4): happy path (synchronousState.Successwith parsed node and original content), empty content (returnsState.Success, notState.Loading), reference-link resolution withlookupLinks = true, and the error path (returnsState.Errorcarrying the throwable instead of throwing)..api/.klib.apidumps for the new function.Checklist: