Skip to content

Commit

Permalink
Merge pull request #219 from mikepenz/fix/use_defined_code_style
Browse files Browse the repository at this point in the history
Fix TextStyle not applied to code in annotated strings
  • Loading branch information
mikepenz authored Oct 10, 2024
2 parents 591dfb3 + a1e8116 commit e676d74
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ fun markdownTypography(
h6: TextStyle = MaterialTheme.typography.h6,
text: TextStyle = MaterialTheme.typography.body1,
code: TextStyle = MaterialTheme.typography.body2.copy(fontFamily = FontFamily.Monospace),
inlineCode: TextStyle = text.copy(fontFamily = FontFamily.Monospace),
quote: TextStyle = MaterialTheme.typography.body2.plus(SpanStyle(fontStyle = FontStyle.Italic)),
paragraph: TextStyle = MaterialTheme.typography.body1,
ordered: TextStyle = MaterialTheme.typography.body1,
Expand All @@ -32,6 +33,6 @@ fun markdownTypography(
),
): MarkdownTypography = DefaultMarkdownTypography(
h1 = h1, h2 = h2, h3 = h3, h4 = h4, h5 = h5, h6 = h6,
text = text, quote = quote, code = code, paragraph = paragraph,
text = text, quote = quote, code = code, inlineCode = inlineCode, paragraph = paragraph,
ordered = ordered, bullet = bullet, list = list, link = link,
)
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ fun markdownTypography(
h6: TextStyle = MaterialTheme.typography.titleLarge,
text: TextStyle = MaterialTheme.typography.bodyLarge,
code: TextStyle = MaterialTheme.typography.bodyMedium.copy(fontFamily = FontFamily.Monospace),
inlineCode: TextStyle = text.copy(fontFamily = FontFamily.Monospace),
quote: TextStyle = MaterialTheme.typography.bodyMedium.plus(SpanStyle(fontStyle = FontStyle.Italic)),
paragraph: TextStyle = MaterialTheme.typography.bodyLarge,
ordered: TextStyle = MaterialTheme.typography.bodyLarge,
Expand All @@ -32,6 +33,6 @@ fun markdownTypography(
),
): MarkdownTypography = DefaultMarkdownTypography(
h1 = h1, h2 = h2, h3 = h3, h4 = h4, h5 = h5, h6 = h6,
text = text, quote = quote, code = code, paragraph = paragraph,
text = text, quote = quote, code = code, inlineCode = inlineCode, paragraph = paragraph,
ordered = ordered, bullet = bullet, list = list, link = link,
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.compose.ui.text.TextStyle
interface MarkdownTypography {
val text: TextStyle
val code: TextStyle
val inlineCode: TextStyle
val h1: TextStyle
val h2: TextStyle
val h3: TextStyle
Expand All @@ -30,6 +31,7 @@ class DefaultMarkdownTypography(
override val h6: TextStyle,
override val text: TextStyle,
override val code: TextStyle,
override val inlineCode: TextStyle,
override val quote: TextStyle,
override val paragraph: TextStyle,
override val ordered: TextStyle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.compose.foundation.text.appendInlineContent
import androidx.compose.runtime.Composable
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextDecoration
Expand Down Expand Up @@ -114,12 +113,12 @@ fun AnnotatedString.Builder.buildMarkdownAnnotatedString(content: String, childr
}

MarkdownElementTypes.CODE_SPAN -> {
val codeStyle = LocalMarkdownTypography.current.inlineCode
pushStyle(
SpanStyle(
fontFamily = FontFamily.Monospace,
codeStyle.copy(
color = LocalMarkdownColors.current.inlineCodeText,
background = LocalMarkdownColors.current.inlineCodeBackground
)
).toSpanStyle()
)
append(' ')
buildMarkdownAnnotatedString(content, child.children.innerList())
Expand Down

0 comments on commit e676d74

Please sign in to comment.