Skip to content

Commit

Permalink
Merge pull request #187 from mikepenz/develop
Browse files Browse the repository at this point in the history
dev -> main
  • Loading branch information
mikepenz authored Jul 19, 2024
2 parents 5624a85 + 04cba46 commit a43cce2
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 40 deletions.
2 changes: 2 additions & 0 deletions app-desktop/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ dependencies {

// required for coil
implementation(libs.coil.network.ktor)
implementation(libs.ktor.client.core)
implementation(libs.ktor.client.java)
implementation(libs.kotlinx.coroutines.swing)
}

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Maven stuff
GROUP=com.mikepenz
VERSION_NAME=0.24.0
VERSION_CODE=2400
VERSION_NAME=0.25.0
VERSION_CODE=2500

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

Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ coil2-svg = { module = "io.coil-kt:coil-svg", version.ref = "coil2" }
markdown = { module = "org.jetbrains:markdown", version.ref = "markdown" }
kotlinx-coroutines-swing = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-swing", version.ref = "coroutines" }
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
ktor-client-java = { module = "io.ktor:ktor-client-java", version.ref = "ktor" }

[plugins]
androidApplication = { id = "com.android.application", version.ref = "agp" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.mikepenz.markdown.compose

import androidx.compose.runtime.compositionLocalOf
import androidx.compose.runtime.staticCompositionLocalOf
import com.mikepenz.markdown.compose.components.MarkdownComponents
import com.mikepenz.markdown.compose.components.markdownComponents
import com.mikepenz.markdown.model.BulletHandler
import com.mikepenz.markdown.model.DefaultMarkdownAnnotator
import com.mikepenz.markdown.model.DefaultMarkdownExtendedSpans
Expand Down Expand Up @@ -82,4 +84,11 @@ val LocalMarkdownAnnotator = compositionLocalOf<MarkdownAnnotator> {
*/
val LocalMarkdownExtendedSpans = compositionLocalOf<MarkdownExtendedSpans> {
return@compositionLocalOf DefaultMarkdownExtendedSpans(null)
}

/**
* Local [MarkdownComponents] provider
*/
val LocalMarkdownComponents = compositionLocalOf<MarkdownComponents> {
return@compositionLocalOf markdownComponents()
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,13 @@
package com.mikepenz.markdown.compose

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Modifier
import com.mikepenz.markdown.compose.components.MarkdownComponentModel
import com.mikepenz.markdown.compose.components.MarkdownComponents
import com.mikepenz.markdown.compose.components.markdownComponents
import com.mikepenz.markdown.model.ImageTransformer
import com.mikepenz.markdown.model.MarkdownAnnotator
import com.mikepenz.markdown.model.MarkdownColors
import com.mikepenz.markdown.model.MarkdownDimens
import com.mikepenz.markdown.model.MarkdownExtendedSpans
import com.mikepenz.markdown.model.MarkdownPadding
import com.mikepenz.markdown.model.MarkdownTypography
import com.mikepenz.markdown.model.NoOpImageTransformerImpl
import com.mikepenz.markdown.model.ReferenceLinkHandlerImpl
import com.mikepenz.markdown.model.markdownAnnotator
import com.mikepenz.markdown.model.markdownDimens
import com.mikepenz.markdown.model.markdownExtendedSpans
import com.mikepenz.markdown.model.markdownPadding
import com.mikepenz.markdown.model.*
import org.intellij.markdown.MarkdownElementTypes.ATX_1
import org.intellij.markdown.MarkdownElementTypes.ATX_2
import org.intellij.markdown.MarkdownElementTypes.ATX_3
Expand Down Expand Up @@ -70,7 +54,8 @@ fun Markdown(
LocalMarkdownTypography provides typography,
LocalImageTransformer provides imageTransformer,
LocalMarkdownAnnotator provides annotator,
LocalMarkdownExtendedSpans provides extendedSpans
LocalMarkdownExtendedSpans provides extendedSpans,
LocalMarkdownComponents provides components,
) {
Column(modifier) {
val parsedTree = MarkdownParser(flavour).buildMarkdownTreeFromString(content)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ data class MarkdownComponentModel(

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

@Composable
fun markdownComponents(
text: MarkdownComponent = CurrentComponentsBridge.text,
eol: MarkdownComponent = CurrentComponentsBridge.eol,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import org.intellij.markdown.ast.ASTNode
@Composable
private fun MarkdownCode(
code: String,
style: TextStyle = LocalMarkdownTypography.current.code
style: TextStyle = LocalMarkdownTypography.current.code,
) {
val backgroundCodeColor = LocalMarkdownColors.current.codeBackground
val codeBackgroundCornerSize = LocalMarkdownDimens.current.codeBackgroundCornerSize
Expand All @@ -50,12 +50,14 @@ private fun MarkdownCode(
@Composable
fun MarkdownCodeFence(
content: String,
node: ASTNode
node: ASTNode,
) {
// CODE_FENCE_START, FENCE_LANG, {content}, CODE_FENCE_END
// CODE_FENCE_START, FENCE_LANG, {content // CODE_FENCE_CONTENT // x-times}, CODE_FENCE_END
// CODE_FENCE_START, EOL, {content // CODE_FENCE_CONTENT // x-times}, EOL
// CODE_FENCE_START, EOL, {content // CODE_FENCE_CONTENT // x-times}
if (node.children.size >= 3) {
val start = node.children[2].startOffset
val end = node.children[node.children.size - 2].endOffset
val end = node.children[(node.children.size - 2).coerceAtLeast(2)].endOffset
MarkdownCode(content.subSequence(start, end).toString().replaceIndent())
} else {
// invalid code block, skipping
Expand All @@ -65,7 +67,7 @@ fun MarkdownCodeFence(
@Composable
fun MarkdownCodeBlock(
content: String,
node: ASTNode
node: ASTNode,
) {
val start = node.children[0].startOffset
val end = node.children[node.children.size - 1].endOffset
Expand All @@ -80,7 +82,7 @@ internal fun MarkdownCodeBackground(
shape: Shape = RectangleShape,
border: BorderStroke? = null,
elevation: Dp = 0.dp,
content: @Composable () -> Unit
content: @Composable () -> Unit,
) {
Box(
modifier = modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,8 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.TextStyle
import com.mikepenz.markdown.compose.LocalBulletListHandler
import com.mikepenz.markdown.compose.LocalMarkdownColors
import com.mikepenz.markdown.compose.LocalMarkdownPadding
import com.mikepenz.markdown.compose.LocalMarkdownTypography
import com.mikepenz.markdown.compose.LocalOrderedListHandler
import com.mikepenz.markdown.compose.components.markdownComponents
import com.mikepenz.markdown.compose.*
import com.mikepenz.markdown.compose.elements.material.MarkdownBasicText
import com.mikepenz.markdown.compose.handleElement
import org.intellij.markdown.MarkdownElementTypes
import org.intellij.markdown.MarkdownElementTypes.ORDERED_LIST
import org.intellij.markdown.MarkdownElementTypes.UNORDERED_LIST
Expand All @@ -30,7 +24,7 @@ fun MarkdownListItems(
node: ASTNode,
style: TextStyle = LocalMarkdownTypography.current.list,
level: Int = 0,
item: @Composable (index: Int, child: ASTNode) -> Unit
item: @Composable (index: Int, child: ASTNode) -> Unit,
) {
val listDp = LocalMarkdownPadding.current.list
val indentListDp = LocalMarkdownPadding.current.indentList
Expand Down Expand Up @@ -62,7 +56,7 @@ fun MarkdownOrderedList(
content: String,
node: ASTNode,
style: TextStyle = LocalMarkdownTypography.current.ordered,
level: Int = 0
level: Int = 0,
) {
val orderedListHandler = LocalOrderedListHandler.current
val listItemBottom = LocalMarkdownPadding.current.listItemBottom
Expand All @@ -81,7 +75,7 @@ fun MarkdownOrderedList(
Column(Modifier.padding(bottom = listItemBottom)) {
handleElement(
node = child,
components = markdownComponents(),
components = LocalMarkdownComponents.current,
content = content,
includeSpacer = false
)
Expand All @@ -95,7 +89,7 @@ fun MarkdownBulletList(
content: String,
node: ASTNode,
style: TextStyle = LocalMarkdownTypography.current.bullet,
level: Int = 0
level: Int = 0,
) {
val bulletHandler = LocalBulletListHandler.current
val listItemBottom = LocalMarkdownPadding.current.listItemBottom
Expand All @@ -114,7 +108,7 @@ fun MarkdownBulletList(
Column(Modifier.padding(bottom = listItemBottom)) {
handleElement(
node = child,
components = markdownComponents(),
components = LocalMarkdownComponents.current,
content = content,
includeSpacer = false
)
Expand Down

0 comments on commit a43cce2

Please sign in to comment.