Skip to content

Commit f5d9340

Browse files
authored
Merge pull request #361 from keta1/fix/handle-element
Remove nested handling of elements in `Markdown` and `LazyMarkdown`
2 parents d58406c + d0c3a25 commit f5d9340

File tree

4 files changed

+14
-22
lines changed
  • multiplatform-markdown-renderer-m2/src/commonMain/kotlin/com/mikepenz/markdown/m2
  • multiplatform-markdown-renderer-m3/src/commonMain/kotlin/com/mikepenz/markdown/m3
  • multiplatform-markdown-renderer/src/commonMain/kotlin/com/mikepenz/markdown/compose

4 files changed

+14
-22
lines changed

multiplatform-markdown-renderer-m2/src/commonMain/kotlin/com/mikepenz/markdown/m2/Markdown.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ fun Markdown(
6969
components: MarkdownComponents = markdownComponents(checkbox = { MarkdownCheckBox(it.content, it.node, it.typography.text) }),
7070
animations: MarkdownAnimations = markdownAnimations(),
7171
referenceLinkHandler: ReferenceLinkHandler = ReferenceLinkHandlerImpl(),
72-
loading: @Composable (modifier: Modifier) -> Unit = { Box(modifier) {} },
72+
loading: @Composable (modifier: Modifier) -> Unit = { Box(modifier) },
7373
success: @Composable (state: State.Success, components: MarkdownComponents, modifier: Modifier) -> Unit = { state, components, modifier ->
7474
MarkdownSuccess(state = state, components = components, modifier = modifier)
7575
},
76-
error: @Composable (modifier: Modifier) -> Unit = { Box(modifier) {} },
76+
error: @Composable (modifier: Modifier) -> Unit = { Box(modifier) },
7777
) = com.mikepenz.markdown.compose.Markdown(
7878
content = content,
7979
colors = colors,
@@ -125,11 +125,11 @@ fun Markdown(
125125
extendedSpans: MarkdownExtendedSpans = markdownExtendedSpans(),
126126
components: MarkdownComponents = markdownComponents(checkbox = { MarkdownCheckBox(it.content, it.node, it.typography.text) }),
127127
animations: MarkdownAnimations = markdownAnimations(),
128-
loading: @Composable (modifier: Modifier) -> Unit = { Box(modifier) {} },
128+
loading: @Composable (modifier: Modifier) -> Unit = { Box(modifier) },
129129
success: @Composable (state: State.Success, components: MarkdownComponents, modifier: Modifier) -> Unit = { state, components, modifier ->
130130
MarkdownSuccess(state = state, components = components, modifier = modifier)
131131
},
132-
error: @Composable (modifier: Modifier) -> Unit = { Box(modifier) {} },
132+
error: @Composable (modifier: Modifier) -> Unit = { Box(modifier) },
133133
) = com.mikepenz.markdown.compose.Markdown(
134134
state = state,
135135
colors = colors,

multiplatform-markdown-renderer-m3/src/commonMain/kotlin/com/mikepenz/markdown/m3/Markdown.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ fun Markdown(
6969
components: MarkdownComponents = markdownComponents(checkbox = { MarkdownCheckBox(it.content, it.node, it.typography.text) }),
7070
animations: MarkdownAnimations = markdownAnimations(),
7171
referenceLinkHandler: ReferenceLinkHandler = ReferenceLinkHandlerImpl(),
72-
loading: @Composable (modifier: Modifier) -> Unit = { Box(modifier) {} },
72+
loading: @Composable (modifier: Modifier) -> Unit = { Box(modifier) },
7373
success: @Composable (state: State.Success, components: MarkdownComponents, modifier: Modifier) -> Unit = { state, components, modifier ->
7474
MarkdownSuccess(state = state, components = components, modifier = modifier)
7575
},
76-
error: @Composable (modifier: Modifier) -> Unit = { Box(modifier) {} },
76+
error: @Composable (modifier: Modifier) -> Unit = { Box(modifier) },
7777
) = com.mikepenz.markdown.compose.Markdown(
7878
content = content,
7979
colors = colors,
@@ -125,11 +125,11 @@ fun Markdown(
125125
extendedSpans: MarkdownExtendedSpans = markdownExtendedSpans(),
126126
components: MarkdownComponents = markdownComponents(checkbox = { MarkdownCheckBox(it.content, it.node, it.typography.text) }),
127127
animations: MarkdownAnimations = markdownAnimations(),
128-
loading: @Composable (modifier: Modifier) -> Unit = { Box(modifier) {} },
128+
loading: @Composable (modifier: Modifier) -> Unit = { Box(modifier) },
129129
success: @Composable (state: State.Success, components: MarkdownComponents, modifier: Modifier) -> Unit = { state, components, modifier ->
130130
MarkdownSuccess(state = state, components = components, modifier = modifier)
131131
},
132-
error: @Composable (modifier: Modifier) -> Unit = { Box(modifier) {} },
132+
error: @Composable (modifier: Modifier) -> Unit = { Box(modifier) },
133133
) = com.mikepenz.markdown.compose.Markdown(
134134
state = state,
135135
colors = colors,

multiplatform-markdown-renderer/src/commonMain/kotlin/com/mikepenz/markdown/compose/LazyMarkdown.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ fun LazyMarkdownSuccess(
2929
contentPadding = contentPadding,
3030
) {
3131
items(state.node.children) { node ->
32-
if (!handleElement(node, components, state.content, skipLinkDefinition = state.linksLookedUp)) {
33-
node.children.forEach { child ->
34-
handleElement(child, components, state.content, skipLinkDefinition = state.linksLookedUp)
35-
}
36-
}
32+
handleElement(node, components, state.content, skipLinkDefinition = state.linksLookedUp)
3733
}
3834
}
3935
}

multiplatform-markdown-renderer/src/commonMain/kotlin/com/mikepenz/markdown/compose/Markdown.kt

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ fun Markdown(
7171
components: MarkdownComponents = markdownComponents(),
7272
animations: MarkdownAnimations = markdownAnimations(),
7373
referenceLinkHandler: ReferenceLinkHandler = ReferenceLinkHandlerImpl(),
74-
loading: @Composable (modifier: Modifier) -> Unit = { Box(modifier) {} },
74+
loading: @Composable (modifier: Modifier) -> Unit = { Box(modifier) },
7575
success: @Composable (state: State.Success, components: MarkdownComponents, modifier: Modifier) -> Unit = { state, components, modifier ->
7676
MarkdownSuccess(state = state, components = components, modifier = modifier)
7777
},
78-
error: @Composable (modifier: Modifier) -> Unit = { Box(modifier) {} },
78+
error: @Composable (modifier: Modifier) -> Unit = { Box(modifier) },
7979
) {
8080
val state = rememberMarkdownState(
8181
content = content,
@@ -133,11 +133,11 @@ fun Markdown(
133133
extendedSpans: MarkdownExtendedSpans = markdownExtendedSpans(),
134134
components: MarkdownComponents = markdownComponents(),
135135
animations: MarkdownAnimations = markdownAnimations(),
136-
loading: @Composable (modifier: Modifier) -> Unit = { Box(modifier) {} },
136+
loading: @Composable (modifier: Modifier) -> Unit = { Box(modifier) },
137137
success: @Composable (state: State.Success, components: MarkdownComponents, modifier: Modifier) -> Unit = { state, components, modifier ->
138138
MarkdownSuccess(state = state, components = components, modifier = modifier)
139139
},
140-
error: @Composable (modifier: Modifier) -> Unit = { Box(modifier) {} },
140+
error: @Composable (modifier: Modifier) -> Unit = { Box(modifier) },
141141
) {
142142
val markdownState by state.state.collectAsState()
143143
CompositionLocalProvider(
@@ -175,11 +175,7 @@ fun MarkdownSuccess(
175175
) {
176176
Column(modifier) {
177177
state.node.children.forEach { node ->
178-
if (!handleElement(node, components, state.content, skipLinkDefinition = state.linksLookedUp)) {
179-
node.children.forEach { child ->
180-
handleElement(child, components, state.content, skipLinkDefinition = state.linksLookedUp)
181-
}
182-
}
178+
handleElement(node, components, state.content, skipLinkDefinition = state.linksLookedUp)
183179
}
184180
}
185181
}

0 commit comments

Comments
 (0)