-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from mikepenz/develop
dev -> main
- Loading branch information
Showing
11 changed files
with
148 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 30 additions & 16 deletions
46
...nderer/src/commonMain/kotlin/com/mikepenz/markdown/compose/elements/MarkdownBlockQuote.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,56 @@ | ||
package com.mikepenz.markdown.compose.elements | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.Text | ||
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 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( | ||
content: String, | ||
node: ASTNode, | ||
style: TextStyle = LocalMarkdownTypography.current.quote | ||
) { | ||
Box( | ||
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 | ||
|
||
Column( | ||
modifier = Modifier | ||
.drawBehind { | ||
drawLine( | ||
color = style.color, | ||
strokeWidth = 2f, | ||
start = Offset(12.dp.value, 0f), | ||
end = Offset(12.dp.value, size.height) | ||
color = blockQuoteColor, | ||
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(start = 16.dp, top = 16.dp, bottom = 16.dp) | ||
.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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...-renderer/src/commonMain/kotlin/com/mikepenz/markdown/compose/elements/MarkdownDivider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.mikepenz.markdown.compose.elements | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.platform.LocalDensity | ||
import androidx.compose.ui.unit.Dp | ||
import androidx.compose.ui.unit.dp | ||
import com.mikepenz.markdown.compose.LocalMarkdownColors | ||
import com.mikepenz.markdown.compose.LocalMarkdownDimens | ||
|
||
@Composable | ||
fun MarkdownDivider( | ||
modifier: Modifier = Modifier, | ||
color: Color = LocalMarkdownColors.current.codeBackground, | ||
thickness: Dp = LocalMarkdownDimens.current.dividerThickness, | ||
) { | ||
val targetThickness = if (thickness == Dp.Hairline) { | ||
(1f / LocalDensity.current.density).dp | ||
} else { | ||
thickness | ||
} | ||
Box( | ||
modifier | ||
.fillMaxWidth() | ||
.height(targetThickness) | ||
.background(color = color) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...orm-markdown-renderer/src/commonMain/kotlin/com/mikepenz/markdown/model/MarkdownDimens.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.mikepenz.markdown.model | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.Immutable | ||
import androidx.compose.ui.unit.Dp | ||
import androidx.compose.ui.unit.dp | ||
|
||
interface MarkdownDimens { | ||
val dividerThickness: Dp | ||
val codeBackgroundCornerSize: Dp | ||
val blockQuoteThickness: Dp | ||
} | ||
|
||
@Immutable | ||
private class DefaultMarkdownDimens( | ||
override val dividerThickness: Dp, | ||
override val codeBackgroundCornerSize: Dp, | ||
override val blockQuoteThickness: Dp, | ||
) : MarkdownDimens | ||
|
||
@Composable | ||
fun markdownDimens( | ||
dividerThickness: Dp = 1.dp, | ||
codeBackgroundCornerSize: Dp = 8.dp, | ||
blockQuoteThickness: Dp = 2.dp, | ||
): MarkdownDimens = DefaultMarkdownDimens( | ||
dividerThickness = dividerThickness, | ||
codeBackgroundCornerSize = codeBackgroundCornerSize, | ||
blockQuoteThickness = blockQuoteThickness, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters