@@ -10,18 +10,18 @@ import androidx.compose.ui.Modifier
1010import androidx.compose.ui.draw.drawBehind
1111import androidx.compose.ui.geometry.Offset
1212import androidx.compose.ui.graphics.isSpecified
13+ import androidx.compose.ui.platform.LocalDensity
1314import androidx.compose.ui.text.TextStyle
1415import androidx.compose.ui.unit.LayoutDirection
15- import androidx.compose.ui.unit.dp
1616import com.mikepenz.markdown.compose.LocalMarkdownColors
1717import com.mikepenz.markdown.compose.LocalMarkdownComponents
1818import com.mikepenz.markdown.compose.LocalMarkdownDimens
1919import com.mikepenz.markdown.compose.LocalMarkdownPadding
2020import com.mikepenz.markdown.compose.LocalMarkdownTypography
2121import com.mikepenz.markdown.compose.MarkdownElement
2222import org.intellij.markdown.MarkdownElementTypes
23+ import org.intellij.markdown.MarkdownTokenTypes.Companion.EOL
2324import org.intellij.markdown.ast.ASTNode
24- import org.intellij.markdown.ast.findChildOfType
2525
2626@Composable
2727fun MarkdownBlockQuote (
@@ -52,25 +52,30 @@ fun MarkdownBlockQuote(
5252 }
5353 .padding(blockQuote)
5454 ) {
55- val nonBlockquotes = node.children.filter { it.type != MarkdownElementTypes .BLOCK_QUOTE }
56- val nestedQuote = node.findChildOfType(MarkdownElementTypes .BLOCK_QUOTE )
57-
58- if (nonBlockquotes.isNotEmpty()) {
59- Column (modifier = Modifier .padding(blockQuoteText)) {
60- nonBlockquotes.onEach { quote ->
61- MarkdownElement (node = quote, components = markdownComponents, content = content, includeSpacer = false )
62- }
55+ val blockQuoteLineHeightInDp = with (LocalDensity .current) { LocalMarkdownTypography .current.quote.fontSize.toDp() }
56+ var priorNestedQuote = false
57+ node.children.onEachIndexed { index, child ->
58+ if (child.type == MarkdownElementTypes .BLOCK_QUOTE ) {
59+ // if block quote is nested, and comes after non block quote, add padding
60+ if (! priorNestedQuote && index != 0 ) Spacer (Modifier .height(blockQuoteText.calculateBottomPadding()))
61+ MarkdownBlockQuote (content = content, node = child, style = style)
62+ priorNestedQuote = true
63+ } else if (child.type == EOL ) {
64+ Spacer (Modifier .height(blockQuoteLineHeightInDp))
65+ } else {
66+ // if first item either completely, or after a nested quote, add top padding
67+ if (index == 0 || priorNestedQuote) Spacer (Modifier .height(blockQuoteText.calculateTopPadding()))
68+ priorNestedQuote = false
69+ MarkdownElement (
70+ node = child,
71+ components = markdownComponents,
72+ content = content,
73+ includeSpacer = false ,
74+ skipLinkDefinition = true
75+ )
76+ // if last item, add bottom padding
77+ if (index == node.children.lastIndex) Spacer (Modifier .height(blockQuoteText.calculateBottomPadding()))
6378 }
64-
65- if (nestedQuote != null ) Spacer (Modifier .height(8 .dp))
66- }
67-
68- if (nestedQuote != null ) {
69- MarkdownBlockQuote (
70- content = content,
71- node = nestedQuote,
72- style = style
73- )
7479 }
7580 }
7681}
0 commit comments