Skip to content

Commit bed8413

Browse files
authored
Merge pull request #395 from mikepenz/fix/391
Improve BlockQuotes
2 parents 218308b + 6dd54d0 commit bed8413

20 files changed

+53
-20
lines changed

MIGRATION.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#### Version 0.34.0
44

55
- **Dependency Upgrade**: Compose 1.8.0 / Compose Multiplatform 1.8.0
6+
- **Breaking Change**: Reordered arguments for `markdownAnnotator` to improve backwards comp.
7+
- **Behavior Change**: Handle empty lines in block quotes. (Using block quote text size as height)
68

79
#### Version 0.33.0
810

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

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ import androidx.compose.ui.Modifier
1010
import androidx.compose.ui.draw.drawBehind
1111
import androidx.compose.ui.geometry.Offset
1212
import androidx.compose.ui.graphics.isSpecified
13+
import androidx.compose.ui.platform.LocalDensity
1314
import androidx.compose.ui.text.TextStyle
1415
import androidx.compose.ui.unit.LayoutDirection
15-
import androidx.compose.ui.unit.dp
1616
import com.mikepenz.markdown.compose.LocalMarkdownColors
1717
import com.mikepenz.markdown.compose.LocalMarkdownComponents
1818
import com.mikepenz.markdown.compose.LocalMarkdownDimens
1919
import com.mikepenz.markdown.compose.LocalMarkdownPadding
2020
import com.mikepenz.markdown.compose.LocalMarkdownTypography
2121
import com.mikepenz.markdown.compose.MarkdownElement
2222
import org.intellij.markdown.MarkdownElementTypes
23+
import org.intellij.markdown.MarkdownTokenTypes.Companion.EOL
2324
import org.intellij.markdown.ast.ASTNode
24-
import org.intellij.markdown.ast.findChildOfType
2525

2626
@Composable
2727
fun 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
}
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)