Skip to content

Commit a43cce2

Browse files
authored
Merge pull request #187 from mikepenz/develop
dev -> main
2 parents 5624a85 + 04cba46 commit a43cce2

File tree

8 files changed

+32
-40
lines changed

8 files changed

+32
-40
lines changed

app-desktop/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ dependencies {
2626

2727
// required for coil
2828
implementation(libs.coil.network.ktor)
29+
implementation(libs.ktor.client.core)
30+
implementation(libs.ktor.client.java)
2931
implementation(libs.kotlinx.coroutines.swing)
3032
}
3133

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Maven stuff
22
GROUP=com.mikepenz
3-
VERSION_NAME=0.24.0
4-
VERSION_CODE=2400
3+
VERSION_NAME=0.25.0
4+
VERSION_CODE=2500
55

66
POM_URL=https://github.com/mikepenz/multiplatform-markdown-renderer
77

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ coil2-svg = { module = "io.coil-kt:coil-svg", version.ref = "coil2" }
3838
markdown = { module = "org.jetbrains:markdown", version.ref = "markdown" }
3939
kotlinx-coroutines-swing = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-swing", version.ref = "coroutines" }
4040
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
41+
ktor-client-java = { module = "io.ktor:ktor-client-java", version.ref = "ktor" }
4142

4243
[plugins]
4344
androidApplication = { id = "com.android.application", version.ref = "agp" }

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/MarkdownCode.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import org.intellij.markdown.ast.ASTNode
2828
@Composable
2929
private fun MarkdownCode(
3030
code: String,
31-
style: TextStyle = LocalMarkdownTypography.current.code
31+
style: TextStyle = LocalMarkdownTypography.current.code,
3232
) {
3333
val backgroundCodeColor = LocalMarkdownColors.current.codeBackground
3434
val codeBackgroundCornerSize = LocalMarkdownDimens.current.codeBackgroundCornerSize
@@ -50,12 +50,14 @@ private fun MarkdownCode(
5050
@Composable
5151
fun MarkdownCodeFence(
5252
content: String,
53-
node: ASTNode
53+
node: ASTNode,
5454
) {
55-
// CODE_FENCE_START, FENCE_LANG, {content}, CODE_FENCE_END
55+
// CODE_FENCE_START, FENCE_LANG, {content // CODE_FENCE_CONTENT // x-times}, CODE_FENCE_END
56+
// CODE_FENCE_START, EOL, {content // CODE_FENCE_CONTENT // x-times}, EOL
57+
// CODE_FENCE_START, EOL, {content // CODE_FENCE_CONTENT // x-times}
5658
if (node.children.size >= 3) {
5759
val start = node.children[2].startOffset
58-
val end = node.children[node.children.size - 2].endOffset
60+
val end = node.children[(node.children.size - 2).coerceAtLeast(2)].endOffset
5961
MarkdownCode(content.subSequence(start, end).toString().replaceIndent())
6062
} else {
6163
// invalid code block, skipping
@@ -65,7 +67,7 @@ fun MarkdownCodeFence(
6567
@Composable
6668
fun MarkdownCodeBlock(
6769
content: String,
68-
node: ASTNode
70+
node: ASTNode,
6971
) {
7072
val start = node.children[0].startOffset
7173
val end = node.children[node.children.size - 1].endOffset
@@ -80,7 +82,7 @@ internal fun MarkdownCodeBackground(
8082
shape: Shape = RectangleShape,
8183
border: BorderStroke? = null,
8284
elevation: Dp = 0.dp,
83-
content: @Composable () -> Unit
85+
content: @Composable () -> Unit,
8486
) {
8587
Box(
8688
modifier = modifier

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)