diff --git a/multiplatform-markdown-renderer/src/commonMain/kotlin/com/mikepenz/markdown/compose/elements/MarkdownBlockQuote.kt b/multiplatform-markdown-renderer/src/commonMain/kotlin/com/mikepenz/markdown/compose/elements/MarkdownBlockQuote.kt index 2e489fb..2f7394a 100644 --- a/multiplatform-markdown-renderer/src/commonMain/kotlin/com/mikepenz/markdown/compose/elements/MarkdownBlockQuote.kt +++ b/multiplatform-markdown-renderer/src/commonMain/kotlin/com/mikepenz/markdown/compose/elements/MarkdownBlockQuote.kt @@ -1,21 +1,20 @@ package com.mikepenz.markdown.compose.elements -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.* import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.draw.drawBehind import androidx.compose.ui.geometry.Offset import androidx.compose.ui.text.TextStyle -import androidx.compose.ui.text.buildAnnotatedString import androidx.compose.ui.unit.LayoutDirection +import androidx.compose.ui.unit.dp import com.mikepenz.markdown.compose.LocalMarkdownColors import com.mikepenz.markdown.compose.LocalMarkdownDimens import com.mikepenz.markdown.compose.LocalMarkdownPadding import com.mikepenz.markdown.compose.LocalMarkdownTypography -import com.mikepenz.markdown.compose.elements.material.Text +import org.intellij.markdown.MarkdownElementTypes import org.intellij.markdown.ast.ASTNode -import org.intellij.markdown.ast.getTextInNode +import org.intellij.markdown.ast.findChildOfType @Composable fun MarkdownBlockQuote( @@ -26,28 +25,32 @@ fun MarkdownBlockQuote( val blockQuoteColor = LocalMarkdownColors.current.text val blockQuoteThickness = LocalMarkdownDimens.current.blockQuoteThickness val blockQuote = LocalMarkdownPadding.current.blockQuote + val blockQuoteText = LocalMarkdownPadding.current.blockQuoteText val blockQuoteBar = LocalMarkdownPadding.current.blockQuoteBar - Box( + + Column( modifier = Modifier .drawBehind { drawLine( color = blockQuoteColor, - strokeWidth = blockQuoteThickness.value, - start = Offset(blockQuoteBar.calculateLeftPadding(LayoutDirection.Ltr).value, 0f), - end = Offset(blockQuoteBar.calculateRightPadding(LayoutDirection.Ltr).value, size.height) + strokeWidth = blockQuoteThickness.toPx(), + start = Offset(blockQuoteBar.calculateStartPadding(LayoutDirection.Ltr).toPx(), blockQuoteBar.calculateTopPadding().toPx()), + end = Offset(blockQuoteBar.calculateStartPadding(LayoutDirection.Ltr).toPx(), size.height - blockQuoteBar.calculateBottomPadding().toPx()) ) } .padding(blockQuote) ) { - val text = buildAnnotatedString { - pushStyle(style.toSpanStyle()) - append(node.getTextInNode(content).toString()) - pop() + val quote = node.findChildOfType(MarkdownElementTypes.PARAGRAPH) + if (quote != null) { + MarkdownParagraph(content, quote, style = style, modifier = Modifier.padding(blockQuoteText)) + } + + val nestedQuote = node.findChildOfType(MarkdownElementTypes.BLOCK_QUOTE) + if (nestedQuote != null) { + if (quote != null) { + Spacer(Modifier.height(8.dp)) + } + MarkdownBlockQuote(content, nestedQuote, style) } - Text( - text, - style, - color = LocalMarkdownColors.current.text, - ) } } diff --git a/multiplatform-markdown-renderer/src/commonMain/kotlin/com/mikepenz/markdown/model/MarkdownPadding.kt b/multiplatform-markdown-renderer/src/commonMain/kotlin/com/mikepenz/markdown/model/MarkdownPadding.kt index 3e57d40..4d30dce 100644 --- a/multiplatform-markdown-renderer/src/commonMain/kotlin/com/mikepenz/markdown/model/MarkdownPadding.kt +++ b/multiplatform-markdown-renderer/src/commonMain/kotlin/com/mikepenz/markdown/model/MarkdownPadding.kt @@ -13,6 +13,7 @@ interface MarkdownPadding { val indentList: Dp val codeBlock: PaddingValues val blockQuote: PaddingValues + val blockQuoteText: PaddingValues val blockQuoteBar: PaddingValues.Absolute } @@ -24,6 +25,7 @@ private class DefaultMarkdownPadding( override val indentList: Dp, override val codeBlock: PaddingValues, override val blockQuote: PaddingValues, + override val blockQuoteText: PaddingValues, override val blockQuoteBar: PaddingValues.Absolute, ) : MarkdownPadding @@ -34,8 +36,9 @@ fun markdownPadding( listItemBottom: Dp = 4.dp, indentList: Dp = 8.dp, codeBlock: PaddingValues = PaddingValues(8.dp), - blockQuote: PaddingValues = PaddingValues(start = 16.dp, top = 16.dp, bottom = 16.dp), - blockQuoteBar: PaddingValues.Absolute = PaddingValues.Absolute(left = 4.dp, right = 4.dp), + blockQuote: PaddingValues = PaddingValues(horizontal = 16.dp, vertical = 0.dp), + blockQuoteText: PaddingValues = PaddingValues(vertical = 4.dp), + blockQuoteBar: PaddingValues.Absolute = PaddingValues.Absolute(left = 4.dp, top = 2.dp, right = 4.dp, bottom = 2.dp), ): MarkdownPadding = DefaultMarkdownPadding( block = block, list = list, @@ -43,5 +46,6 @@ fun markdownPadding( indentList = indentList, codeBlock = codeBlock, blockQuote = blockQuote, + blockQuoteText = blockQuoteText, blockQuoteBar = blockQuoteBar, )