Skip to content

Commit f99d7f7

Browse files
authored
Merge pull request #186 from mikepenz/feature/184
Ensure custom `MarkdownComponents` are also available to `Lists`
2 parents 1768f4c + 9f4c119 commit f99d7f7

File tree

4 files changed

+19
-32
lines changed

4 files changed

+19
-32
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package com.mikepenz.markdown.compose
22

33
import androidx.compose.runtime.compositionLocalOf
44
import androidx.compose.runtime.staticCompositionLocalOf
5+
import com.mikepenz.markdown.compose.components.MarkdownComponents
6+
import com.mikepenz.markdown.compose.components.markdownComponents
57
import com.mikepenz.markdown.model.BulletHandler
68
import com.mikepenz.markdown.model.DefaultMarkdownAnnotator
79
import com.mikepenz.markdown.model.DefaultMarkdownExtendedSpans
@@ -82,4 +84,11 @@ val LocalMarkdownAnnotator = compositionLocalOf<MarkdownAnnotator> {
8284
*/
8385
val LocalMarkdownExtendedSpans = compositionLocalOf<MarkdownExtendedSpans> {
8486
return@compositionLocalOf DefaultMarkdownExtendedSpans(null)
87+
}
88+
89+
/**
90+
* Local [MarkdownComponents] provider
91+
*/
92+
val LocalMarkdownComponents = compositionLocalOf<MarkdownComponents> {
93+
return@compositionLocalOf markdownComponents()
8594
}

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

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,13 @@
11
package com.mikepenz.markdown.compose
22

3-
import androidx.compose.foundation.layout.Column
4-
import androidx.compose.foundation.layout.ColumnScope
5-
import androidx.compose.foundation.layout.Spacer
6-
import androidx.compose.foundation.layout.fillMaxSize
7-
import androidx.compose.foundation.layout.height
3+
import androidx.compose.foundation.layout.*
84
import androidx.compose.runtime.Composable
95
import androidx.compose.runtime.CompositionLocalProvider
106
import androidx.compose.ui.Modifier
117
import com.mikepenz.markdown.compose.components.MarkdownComponentModel
128
import com.mikepenz.markdown.compose.components.MarkdownComponents
139
import com.mikepenz.markdown.compose.components.markdownComponents
14-
import com.mikepenz.markdown.model.ImageTransformer
15-
import com.mikepenz.markdown.model.MarkdownAnnotator
16-
import com.mikepenz.markdown.model.MarkdownColors
17-
import com.mikepenz.markdown.model.MarkdownDimens
18-
import com.mikepenz.markdown.model.MarkdownExtendedSpans
19-
import com.mikepenz.markdown.model.MarkdownPadding
20-
import com.mikepenz.markdown.model.MarkdownTypography
21-
import com.mikepenz.markdown.model.NoOpImageTransformerImpl
22-
import com.mikepenz.markdown.model.ReferenceLinkHandlerImpl
23-
import com.mikepenz.markdown.model.markdownAnnotator
24-
import com.mikepenz.markdown.model.markdownDimens
25-
import com.mikepenz.markdown.model.markdownExtendedSpans
26-
import com.mikepenz.markdown.model.markdownPadding
10+
import com.mikepenz.markdown.model.*
2711
import org.intellij.markdown.MarkdownElementTypes.ATX_1
2812
import org.intellij.markdown.MarkdownElementTypes.ATX_2
2913
import org.intellij.markdown.MarkdownElementTypes.ATX_3
@@ -70,7 +54,8 @@ fun Markdown(
7054
LocalMarkdownTypography provides typography,
7155
LocalImageTransformer provides imageTransformer,
7256
LocalMarkdownAnnotator provides annotator,
73-
LocalMarkdownExtendedSpans provides extendedSpans
57+
LocalMarkdownExtendedSpans provides extendedSpans,
58+
LocalMarkdownComponents provides components,
7459
) {
7560
Column(modifier) {
7661
val parsedTree = MarkdownParser(flavour).buildMarkdownTreeFromString(content)

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ data class MarkdownComponentModel(
3131

3232
private fun MarkdownComponentModel.getTextInNode() = node.getTextInNode(content)
3333

34-
@Composable
3534
fun markdownComponents(
3635
text: MarkdownComponent = CurrentComponentsBridge.text,
3736
eol: MarkdownComponent = CurrentComponentsBridge.eol,

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,8 @@ import androidx.compose.foundation.layout.padding
77
import androidx.compose.runtime.Composable
88
import androidx.compose.ui.Modifier
99
import androidx.compose.ui.text.TextStyle
10-
import com.mikepenz.markdown.compose.LocalBulletListHandler
11-
import com.mikepenz.markdown.compose.LocalMarkdownColors
12-
import com.mikepenz.markdown.compose.LocalMarkdownPadding
13-
import com.mikepenz.markdown.compose.LocalMarkdownTypography
14-
import com.mikepenz.markdown.compose.LocalOrderedListHandler
15-
import com.mikepenz.markdown.compose.components.markdownComponents
10+
import com.mikepenz.markdown.compose.*
1611
import com.mikepenz.markdown.compose.elements.material.MarkdownBasicText
17-
import com.mikepenz.markdown.compose.handleElement
1812
import org.intellij.markdown.MarkdownElementTypes
1913
import org.intellij.markdown.MarkdownElementTypes.ORDERED_LIST
2014
import org.intellij.markdown.MarkdownElementTypes.UNORDERED_LIST
@@ -30,7 +24,7 @@ fun MarkdownListItems(
3024
node: ASTNode,
3125
style: TextStyle = LocalMarkdownTypography.current.list,
3226
level: Int = 0,
33-
item: @Composable (index: Int, child: ASTNode) -> Unit
27+
item: @Composable (index: Int, child: ASTNode) -> Unit,
3428
) {
3529
val listDp = LocalMarkdownPadding.current.list
3630
val indentListDp = LocalMarkdownPadding.current.indentList
@@ -62,7 +56,7 @@ fun MarkdownOrderedList(
6256
content: String,
6357
node: ASTNode,
6458
style: TextStyle = LocalMarkdownTypography.current.ordered,
65-
level: Int = 0
59+
level: Int = 0,
6660
) {
6761
val orderedListHandler = LocalOrderedListHandler.current
6862
val listItemBottom = LocalMarkdownPadding.current.listItemBottom
@@ -81,7 +75,7 @@ fun MarkdownOrderedList(
8175
Column(Modifier.padding(bottom = listItemBottom)) {
8276
handleElement(
8377
node = child,
84-
components = markdownComponents(),
78+
components = LocalMarkdownComponents.current,
8579
content = content,
8680
includeSpacer = false
8781
)
@@ -95,7 +89,7 @@ fun MarkdownBulletList(
9589
content: String,
9690
node: ASTNode,
9791
style: TextStyle = LocalMarkdownTypography.current.bullet,
98-
level: Int = 0
92+
level: Int = 0,
9993
) {
10094
val bulletHandler = LocalBulletListHandler.current
10195
val listItemBottom = LocalMarkdownPadding.current.listItemBottom
@@ -114,7 +108,7 @@ fun MarkdownBulletList(
114108
Column(Modifier.padding(bottom = listItemBottom)) {
115109
handleElement(
116110
node = child,
117-
components = markdownComponents(),
111+
components = LocalMarkdownComponents.current,
118112
content = content,
119113
includeSpacer = false
120114
)

0 commit comments

Comments
 (0)