You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* @param content The markdown content to be rendered.
43
-
* @param colors The colors to be used for rendering.
44
-
* @param typography The typography to be used for rendering.
45
-
* @param modifier The modifier to be applied to the container.
46
-
* @param padding The padding to be applied to the container.
47
-
* @param dimens The dimensions to be used for rendering.
48
-
* @param flavour The flavour descriptor for parsing the markdown. By default uses GFM flavour.
49
-
* @param parser The parser to be used for parsing the markdown. By default uses the flavour supplied.
50
-
* @param imageTransformer The image transformer to be used for rendering images.
51
-
* @param annotator The annotator to be used for rendering annotations.
52
-
* @param extendedSpans The extended spans to be used for rendering.
53
-
* @param inlineContent The inline content to be rendered.
54
-
* @param components The components to be used for rendering.
55
-
* @param referenceLinkHandler The reference link handler to be used for handling links.
56
-
* @param animations The animations to be used for rendering.
57
-
* @param loading A composable function to be displayed while loading the content.
58
-
* @param success A composable function to be displayed with the markdown content. It receives the modifier, state and components as parameters. By default this is a [Column].
59
-
* @param error A composable function to be displayed in case of an error. Only really possible if assertions are enabled on the parser)
40
+
* Renders the provided markdown content string using Jetpack Compose.
41
+
*
42
+
* This is the primary entry point for rendering markdown content in your application.
43
+
* It handles parsing the markdown string, applying styling, and rendering the content
44
+
* with appropriate components.
45
+
*
46
+
* The rendering process follows these steps:
47
+
* 1. Parse the markdown content using the provided parser
48
+
* 2. Create a state object to manage the rendering process
49
+
* 3. Apply styling and customization options
50
+
* 4. Render the content using the appropriate components
51
+
*
52
+
* Example usage:
53
+
* ```
54
+
* Markdown(
55
+
* content = "# Hello World\n\nThis is a **bold** statement.",
56
+
* colors = markdownColor(),
57
+
* typography = markdownTypography()
58
+
* )
59
+
* ```
60
+
*
61
+
* @param content The markdown content string to be rendered.
62
+
* @param colors The color scheme to be used for rendering different markdown elements.
63
+
* @param typography The typography settings to be used for text rendering.
64
+
* @param modifier The modifier to be applied to the container. Defaults to [Modifier.fillMaxSize].
65
+
* @param padding The padding configuration to be applied to different markdown elements.
66
+
* @param dimens The dimension settings for spacing and sizing of markdown elements.
67
+
* @param flavour The markdown flavor descriptor for parsing. By default uses GitHub Flavored Markdown (GFM).
68
+
* @param parser The parser instance to be used for parsing the markdown. By default creates a new parser with the provided flavor.
69
+
* @param imageTransformer The transformer for handling and loading images within markdown content.
70
+
* @param annotator The annotator for adding custom annotations to the rendered content.
71
+
* @param extendedSpans The configuration for extended text spans beyond standard markdown.
72
+
* @param inlineContent The configuration for inline custom content within markdown.
73
+
* @param components The custom components to be used for rendering different markdown elements.
74
+
* @param referenceLinkHandler The handler for resolving reference-style links in markdown.
75
+
* @param animations The animation configurations for interactive elements.
76
+
* @param loading A composable function to be displayed while the content is being parsed and prepared.
77
+
* @param success A composable function to be displayed with the successfully parsed markdown content.
78
+
* It receives the state, components, and modifier as parameters.
79
+
* By default, this renders the content in a [Column].
80
+
* @param error A composable function to be displayed in case of parsing errors.
81
+
* This is only triggered if assertions are enabled on the parser.
60
82
*/
61
83
@Composable
62
84
funMarkdown(
@@ -108,23 +130,48 @@ fun Markdown(
108
130
}
109
131
110
132
/**
111
-
* Renders the markdown content.
112
-
*
113
-
* @param markdownState The markdown state to be rendered.
114
-
* @param colors The colors to be used for rendering.
115
-
* @param typography The typography to be used for rendering.
116
-
* @param modifier The modifier to be applied to the container.
117
-
* @param padding The padding to be applied to the container.
118
-
* @param dimens The dimensions to be used for rendering.
119
-
* @param imageTransformer The image transformer to be used for rendering images.
120
-
* @param annotator The annotator to be used for rendering annotations.
121
-
* @param extendedSpans The extended spans to be used for rendering.
122
-
* @param inlineContent The inline content to be rendered.
123
-
* @param components The components to be used for rendering.
124
-
* @param animations The animations to be used for rendering.
125
-
* @param loading A composable function to be displayed while loading the content.
126
-
* @param success A composable function to be displayed with the markdown content. It receives the modifier, state and components as parameters. By default this is a [Column].
127
-
* @param error A composable function to be displayed in case of an error. Only really possible if assertions are enabled on the parser)
133
+
* Renders markdown content using a pre-created [MarkdownState] object.
134
+
*
135
+
* This overload is useful when you need more control over the state management
136
+
* of your markdown content, such as when you want to:
137
+
* - Pre-parse markdown content
138
+
* - Share the same state across multiple composables
139
+
* - Implement custom state handling logic
140
+
*
141
+
* The state object manages the parsing and preparation of the markdown content,
142
+
* while this function handles the rendering with appropriate styling and components.
143
+
*
144
+
* Example usage:
145
+
* ```
146
+
* val markdownState = rememberMarkdownState(content = "# Hello World")
147
+
*
148
+
* Markdown(
149
+
* markdownState = markdownState,
150
+
* colors = markdownColor(),
151
+
* typography = markdownTypography()
152
+
* )
153
+
* ```
154
+
*
155
+
* @param markdownState A [MarkdownState] object that manages the parsing and state of the markdown content.
156
+
* @param colors The color scheme to be used for rendering different markdown elements.
157
+
* @param typography The typography settings to be used for text rendering.
158
+
* @param modifier The modifier to be applied to the container. Defaults to [Modifier.fillMaxSize].
159
+
* @param padding The padding configuration to be applied to different markdown elements.
160
+
* @param dimens The dimension settings for spacing and sizing of markdown elements.
161
+
* @param imageTransformer The transformer for handling and loading images within markdown content.
162
+
* @param annotator The annotator for adding custom annotations to the rendered content.
163
+
* @param extendedSpans The configuration for extended text spans beyond standard markdown.
164
+
* @param inlineContent The configuration for inline custom content within markdown.
165
+
* @param components The custom components to be used for rendering different markdown elements.
166
+
* @param animations The animation configurations for interactive elements.
167
+
* @param loading A composable function to be displayed while the content is being parsed and prepared.
168
+
* @param success A composable function to be displayed with the successfully parsed markdown content.
169
+
* It receives the state, components, and modifier as parameters.
170
+
* By default, this renders the content in a [Column].
171
+
* @param error A composable function to be displayed in case of parsing errors.
172
+
* This is only triggered if assertions are enabled on the parser.
173
+
*
174
+
* @see rememberMarkdownState
128
175
*/
129
176
@Composable
130
177
funMarkdown(
@@ -168,23 +215,53 @@ fun Markdown(
168
215
169
216
170
217
/**
171
-
* Renders the markdown content.
172
-
*
173
-
* @param state The markdown state to be rendered.
174
-
* @param colors The colors to be used for rendering.
175
-
* @param typography The typography to be used for rendering.
176
-
* @param modifier The modifier to be applied to the container.
177
-
* @param padding The padding to be applied to the container.
178
-
* @param dimens The dimensions to be used for rendering.
179
-
* @param imageTransformer The image transformer to be used for rendering images.
180
-
* @param annotator The annotator to be used for rendering annotations.
181
-
* @param extendedSpans The extended spans to be used for rendering.
182
-
* @param inlineContent The inline content to be rendered.
183
-
* @param components The components to be used for rendering.
184
-
* @param animations The animations to be used for rendering.
185
-
* @param loading A composable function to be displayed while loading the content.
186
-
* @param success A composable function to be displayed with the markdown content. It receives the modifier, state and components as parameters. By default this is a [Column].
187
-
* @param error A composable function to be displayed in case of an error. Only really possible if assertions are enabled on the parser)
218
+
* Renders markdown content using a [State] object directly.
219
+
*
220
+
* This is the lowest-level overload of the Markdown composable, providing direct control
221
+
* over the rendering state. It's primarily used internally by the other overloads but
222
+
* can be useful for advanced use cases where you need to:
223
+
* - Implement custom state transitions
224
+
* - Handle specific loading/error states manually
225
+
* - Integrate with custom state management systems
226
+
*
227
+
* The function handles different states (Loading, Success, Error) and provides
228
+
* appropriate UI for each state.
229
+
*
230
+
* Example usage:
231
+
* ```
232
+
* val state: State = ... // Your custom state implementation
233
+
*
234
+
* Markdown(
235
+
* state = state,
236
+
* colors = markdownColor(),
237
+
* typography = markdownTypography(),
238
+
* loading = { LoadingIndicator() },
239
+
* error = { ErrorMessage() }
240
+
* )
241
+
* ```
242
+
*
243
+
* @param state A [State] object representing the current state of the markdown content (loading, success, or error).
244
+
* @param colors The color scheme to be used for rendering different markdown elements.
245
+
* @param typography The typography settings to be used for text rendering.
246
+
* @param modifier The modifier to be applied to the container. Defaults to [Modifier.fillMaxSize].
247
+
* @param padding The padding configuration to be applied to different markdown elements.
248
+
* @param dimens The dimension settings for spacing and sizing of markdown elements.
249
+
* @param imageTransformer The transformer for handling and loading images within markdown content.
250
+
* @param annotator The annotator for adding custom annotations to the rendered content.
251
+
* @param extendedSpans The configuration for extended text spans beyond standard markdown.
252
+
* @param inlineContent The configuration for inline custom content within markdown.
253
+
* @param components The custom components to be used for rendering different markdown elements.
254
+
* @param animations The animation configurations for interactive elements.
255
+
* @param loading A composable function to be displayed when the state is [State.Loading].
256
+
* @param success A composable function to be displayed when the state is [State.Success].
257
+
* It receives the state, components, and modifier as parameters.
258
+
* By default, this renders the content in a [Column].
259
+
* @param error A composable function to be displayed when the state is [State.Error].
260
+
*
261
+
* @see State
262
+
* @see State.Loading
263
+
* @see State.Success
264
+
* @see State.Error
188
265
*/
189
266
@Composable
190
267
funMarkdown(
@@ -228,11 +305,35 @@ fun Markdown(
228
305
}
229
306
230
307
/**
231
-
* Renders the parsed markdown content.
308
+
* Renders the successfully parsed markdown content in a Column layout.
309
+
*
310
+
* This function is used internally by the [Markdown] composable when the state is [State.Success].
311
+
* It iterates through the parsed markdown nodes and renders each element using the appropriate
312
+
* component from the provided [MarkdownComponents].
232
313
*
233
-
* @param state The success markdown state.
234
-
* @param components The MarkdownComponents instance containing the components to use.
235
-
* @param modifier The modifier to be applied to the container.
314
+
* You can use this function directly if you have a custom state management system and
315
+
* want to render only the success state of markdown content.
316
+
*
317
+
* Example usage:
318
+
* ```
319
+
* val successState: State.Success = ... // Your parsed markdown state
320
+
* val components = markdownComponents()
321
+
*
322
+
* MarkdownSuccess(
323
+
* state = successState,
324
+
* components = components,
325
+
* modifier = Modifier.padding(16.dp)
326
+
* )
327
+
* ```
328
+
*
329
+
* @param state The [State.Success] object containing the parsed markdown content and node tree.
330
+
* @param components The [MarkdownComponents] instance containing the components to use for rendering
331
+
* different markdown elements.
332
+
* @param modifier The modifier to be applied to the container Column.
0 commit comments