Change markdown headline typography

This commit is contained in:
MM20 2023-04-26 21:43:15 +02:00
parent db79a19ebc
commit 624a6a6d2e
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
2 changed files with 47 additions and 47 deletions

View File

@ -104,12 +104,12 @@ fun ChildNodes(node: ASTNode, text: String, onTextChange: (String) -> Unit) {
fun AtxNode(node: ASTNode, text: String, level: Int, onTextChange: (String) -> Unit) { fun AtxNode(node: ASTNode, text: String, level: Int, onTextChange: (String) -> Unit) {
ProvideTextStyle( ProvideTextStyle(
when (level) { when (level) {
1 -> MaterialTheme.typography.headlineLarge 1 -> MaterialTheme.typography.titleLarge
2 -> MaterialTheme.typography.headlineMedium 2 -> MaterialTheme.typography.titleMedium
3 -> MaterialTheme.typography.headlineSmall 3 -> MaterialTheme.typography.titleSmall
4 -> MaterialTheme.typography.titleLarge 4 -> MaterialTheme.typography.labelLarge
5 -> MaterialTheme.typography.titleMedium 5 -> MaterialTheme.typography.labelMedium
else -> MaterialTheme.typography.titleSmall else -> MaterialTheme.typography.labelSmall
} }
) { ) {
ChildNodes(node, text, onTextChange) ChildNodes(node, text, onTextChange)

View File

@ -45,45 +45,6 @@ fun AnnotatedString.Builder.applyStyles(
) )
} }
MarkdownElementTypes.ATX_1 -> { MarkdownElementTypes.ATX_1 -> {
addStyle(
typography.headlineLarge.toSpanStyle(),
node.startOffset - rootOffset,
node.endOffset - rootOffset,
)
addStyle(
typography.headlineLarge.toParagraphStyle(),
node.startOffset - rootOffset,
min(node.endOffset + 1 - rootOffset, length)
)
}
MarkdownElementTypes.ATX_2 -> {
addStyle(
typography.headlineMedium.toSpanStyle(),
node.startOffset - rootOffset,
node.endOffset - rootOffset,
)
addStyle(
typography.headlineMedium.toParagraphStyle(),
node.startOffset - rootOffset,
min(node.endOffset + 1 - rootOffset, length)
)
}
MarkdownElementTypes.ATX_3 -> {
addStyle(
typography.headlineSmall.toSpanStyle(),
node.startOffset - rootOffset,
node.endOffset - rootOffset,
)
addStyle(
typography.headlineSmall.toParagraphStyle(),
node.startOffset - rootOffset,
min(node.endOffset + 1 - rootOffset, length)
)
}
MarkdownElementTypes.ATX_4 -> {
addStyle( addStyle(
typography.titleLarge.toSpanStyle(), typography.titleLarge.toSpanStyle(),
node.startOffset - rootOffset, node.startOffset - rootOffset,
@ -96,7 +57,7 @@ fun AnnotatedString.Builder.applyStyles(
) )
} }
MarkdownElementTypes.ATX_5 -> { MarkdownElementTypes.ATX_2 -> {
addStyle( addStyle(
typography.titleMedium.toSpanStyle(), typography.titleMedium.toSpanStyle(),
node.startOffset - rootOffset, node.startOffset - rootOffset,
@ -109,7 +70,7 @@ fun AnnotatedString.Builder.applyStyles(
) )
} }
MarkdownElementTypes.ATX_6 -> { MarkdownElementTypes.ATX_3 -> {
addStyle( addStyle(
typography.titleSmall.toSpanStyle(), typography.titleSmall.toSpanStyle(),
node.startOffset - rootOffset, node.startOffset - rootOffset,
@ -121,6 +82,45 @@ fun AnnotatedString.Builder.applyStyles(
min(node.endOffset + 1 - rootOffset, length) min(node.endOffset + 1 - rootOffset, length)
) )
} }
MarkdownElementTypes.ATX_4 -> {
addStyle(
typography.labelLarge.toSpanStyle(),
node.startOffset - rootOffset,
node.endOffset - rootOffset,
)
addStyle(
typography.labelLarge.toParagraphStyle(),
node.startOffset - rootOffset,
min(node.endOffset + 1 - rootOffset, length)
)
}
MarkdownElementTypes.ATX_5 -> {
addStyle(
typography.labelMedium.toSpanStyle(),
node.startOffset - rootOffset,
node.endOffset - rootOffset,
)
addStyle(
typography.labelMedium.toParagraphStyle(),
node.startOffset - rootOffset,
min(node.endOffset + 1 - rootOffset, length)
)
}
MarkdownElementTypes.ATX_6 -> {
addStyle(
typography.labelSmall.toSpanStyle(),
node.startOffset - rootOffset,
node.endOffset - rootOffset,
)
addStyle(
typography.labelSmall.toParagraphStyle(),
node.startOffset - rootOffset,
min(node.endOffset + 1 - rootOffset, length)
)
}
} }
for (child in node.children) { for (child in node.children) {
applyStyles(child, typography, delimiterStyle, rootOffset) applyStyles(child, typography, delimiterStyle, rootOffset)