Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Documentation/style-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,10 @@ Visual styling using CSS-like variable names. All properties in the `theme` obje
|--------------|-----------------|------|---------|-------------|
| `--font-family` | `typography.fontFamily` | `String` | `null` (system font) | Font family name |
| `--line-height-body` | `typography.lineHeight` | `Double` | `1.0` | Line height multiplier |
| `--message-font-size` | `typography.fontSize` | `Double` | `null` (Material default) | Message body text size (px) |
| `--message-font-weight` | `typography.fontWeight` | `Int` | `null` (Material default) | Message body text weight (`100`–`900`, `normal`, `bold`) |
| `--message-concierge-link-font-weight` | `typography.linkFontWeight` | `Int?` | `null` (inherits body weight) | Inline hyperlink text weight in concierge messages |
| `--message-concierge-link-underline` | `typography.linkUnderline` | `Boolean` | `true` | Whether inline hyperlinks are underlined (WCAG 1.4.1) |

### Colors - Primary

Expand Down Expand Up @@ -1551,6 +1555,10 @@ This section documents which properties are fully implemented, partially impleme
|--------------|--------|-------|---------|
| `--font-family` | ⚠️ | Parsed but not implemented | - |
| `--line-height-body` | ✅ | Body text line height | All text components via `ConciergeStyles.withThemeTypography` |
| `--message-font-size` | ✅ | Message body text size | `ConciergeStyles.withThemeTypography` |
| `--message-font-weight` | ✅ | Message body text weight | `ConciergeStyles.withThemeTypography` |
| `--message-concierge-link-font-weight` | ✅ | Inline link text weight | `MarkdownRenderer` link renderers |
| `--message-concierge-link-underline` | ✅ | Inline link underline | `MarkdownRenderer` link renderers |
| `--input-font-size` | ✅ | Input field text size | `ChatTextField` |
| `--citations-desktop-button-font-size` | ✅ | Citation pill text size | `CircularCitation` |
| `--disclaimer-font-size` | ✅ | Disclaimer text size | `ConciergeDisclaimer` (DisclaimerStyle) |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,34 @@ internal object CSSKeyMapper {
?: ConciergeTypography(lineHeight = lineHeight)
)
},
"message-font-size" to { cssValue, theme ->
val fontSize = CSSValueConverter.parsePxValue(cssValue)
theme.copy(
typography = theme.typography?.copy(fontSize = fontSize)
?: ConciergeTypography(fontSize = fontSize)
)
},
"message-font-weight" to { cssValue, theme ->
val fontWeight = CSSValueConverter.parseFontWeight(cssValue)
theme.copy(
typography = theme.typography?.copy(fontWeight = fontWeight)
?: ConciergeTypography(fontWeight = fontWeight)
)
},
"message-concierge-link-font-weight" to { cssValue, theme ->
val linkFontWeight = CSSValueConverter.parseFontWeight(cssValue)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[LOW] parseFontWeight turns an unreadable value (e.g. "heavy") into 400 instead of null. For link weight, that 400 then overrides FontWeight.Bold on **[text](url)** links. parseFontWeightOrNull plus a 1–1000 range check here (and for message-font-weight above) would fall back to the default look and also fix the crash.

theme.copy(
typography = theme.typography?.copy(linkFontWeight = linkFontWeight)
?: ConciergeTypography(linkFontWeight = linkFontWeight)
)
},
"message-concierge-link-underline" to { cssValue, theme ->
val linkUnderline = cssValue.trim().equals("false", ignoreCase = true).not()
theme.copy(
typography = theme.typography?.copy(linkUnderline = linkUnderline)
?: ConciergeTypography(linkUnderline = linkUnderline)
)
},

// Colors - Primary/Surface/Message/Button/Input/Feedback/Citations/Prompt Pill/Prompt Suggestions
// are generated below via colorCssAssignments -- the couple of bespoke ones that don't fit the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ internal object ConciergeStyles {
return this.copy(
// Note: Font family would require loading custom fonts, which is not implemented yet
// fontFamily = typography.fontFamily?.let { FontFamily(...) },
lineHeight = typography.lineHeight?.let { (this.fontSize.value * it).sp } ?: this.lineHeight
fontSize = typography.fontSize?.sp ?: this.fontSize,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[LOW] parsePxValue accepts "0" and negative values, which would hide or break message text. Should this only accept values above 0 (in the mapper or here)?

fontWeight = typography.fontWeight?.let { FontWeight(it) } ?: this.fontWeight,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[HIGH] parseFontWeight accepts any whole number, but Compose's FontWeight(Int) throws IllegalArgumentException outside 1–1000. A theme value like "0" or "1001" would then crash every message bubble, since this style is used by messageBubbleStyle. The disclaimer style already guards against this with FontWeight(w.coerceIn(100, 900)) (around line 961). Could you do the same here, or better, reject out-of-range values in CSSKeyMapper so the token never holds an invalid weight?

lineHeight = typography.lineHeight?.let { ((typography.fontSize?.toFloat() ?: this.fontSize.value) * it).sp } ?: this.lineHeight
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ data class ConciergeThemeTokens(
*/
data class ConciergeTypography(
val fontFamily: String? = null,
val lineHeight: Double? = null
val lineHeight: Double? = null,
/** Message body font size in sp. When null, the Material default for the text style is used. */
val fontSize: Double? = null,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[LOW] ConciergeTypography is a public data class, so adding fields changes its JVM constructor and copy signatures. Apps already compiled against the old (String, Double) constructor would hit NoSuchMethodError until they recompile. This repo already changes public theme classes this way, so it's probably fine, but worth a line in the release notes rather than calling it fully backward compatible.

/** Message body font weight (100-900). When null, the text style default is used. */
val fontWeight: Int? = null,
/** Font weight applied to inline hyperlinks in message text. When null, links inherit [fontWeight]. */
val linkFontWeight: Int? = null,
/** Whether inline hyperlinks in message text are underlined. Defaults to true (WCAG 1.4.1). */
val linkUnderline: Boolean = true
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ package com.adobe.marketing.mobile.concierge.utils.markdown

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import com.adobe.marketing.mobile.concierge.ConciergeConstants
Expand Down Expand Up @@ -44,6 +45,9 @@ internal object MarkdownParser {
val messageTextStyle = messageBubbleStyle.textStyle.copy(color = messageBubbleStyle.botMessageTextColor)
val darkTheme = isSystemInDarkTheme()
val linkColor = ConciergeTheme.colors.messageConciergeLink ?: ConciergeTheme.colors.onSurface
val typography = ConciergeTheme.tokens?.typography
val linkFontWeight = typography?.linkFontWeight?.let { FontWeight(it) }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[HIGH] Same range problem as ConciergeStyles.kt:103. This runs for every bot message, even ones with no links, so an out-of-range --message-concierge-link-font-weight crashes plain assistant text too.

val linkUnderline = typography?.linkUnderline ?: true

// Memoize the rendered AnnotatedString. Without this, MarkdownRenderer.render() re-runs on
// every recomposition for every visible message, rebuilding the full AnnotatedString. During
Expand All @@ -57,13 +61,13 @@ internal object MarkdownParser {
// itself is NOT used as a key — ConciergeTheme.colorScheme builds a fresh ColorScheme on every
// read and ColorScheme has only reference equality, so keying on it would invalidate the cache
// every recomposition and defeat the memoization entirely.
return remember(markdown, linkHints, messageTextStyle, linkColor, darkTheme) {
return remember(markdown, linkHints, messageTextStyle, linkColor, linkFontWeight, linkUnderline, darkTheme) {
Log.debug(
ConciergeConstants.EXTENSION_NAME,
TAG,
"Parsed ${tokens.size} tokens, starting rendering."
)
MarkdownRenderer.render(markdown, tokens, colorScheme, messageTextStyle, linkHints, linkColor)
MarkdownRenderer.render(markdown, tokens, colorScheme, messageTextStyle, linkHints, linkColor, linkFontWeight, linkUnderline)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ internal object MarkdownRenderer {
colorScheme: ColorScheme,
baseTextStyle: TextStyle,
linkHints: List<LinkHint> = emptyList(),
linkColor: Color = Color.Unspecified
linkColor: Color = Color.Unspecified,
linkFontWeight: FontWeight? = null,
linkUnderline: Boolean = true
): AnnotatedString {
Log.debug(
ConciergeConstants.EXTENSION_NAME,
Expand All @@ -91,7 +93,7 @@ internal object MarkdownRenderer {
if (token.start < currentIndex) return@forEach

appendGapText(markdown, currentIndex, token.start, builder, colorScheme, baseTextStyle)
renderToken(token, builder, colorScheme, baseTextStyle, resolvedLinkColor, linkHintByHref)
renderToken(token, builder, colorScheme, baseTextStyle, resolvedLinkColor, linkHintByHref, linkFontWeight, linkUnderline)
currentIndex = token.end
}

Expand Down Expand Up @@ -134,14 +136,16 @@ internal object MarkdownRenderer {
colorScheme: ColorScheme,
baseTextStyle: TextStyle,
linkColor: Color,
linkHintByHref: Map<String, String> = emptyMap()
linkHintByHref: Map<String, String> = emptyMap(),
linkFontWeight: FontWeight? = null,
linkUnderline: Boolean = true
) {
when (token.type) {
TokenType.CODE_BLOCK -> renderCodeBlock(token, builder, colorScheme, baseTextStyle)
TokenType.INLINE_CODE -> renderInlineCode(token, builder, colorScheme, baseTextStyle)
TokenType.BOLD_LINK -> renderBoldLink(token, builder, colorScheme, baseTextStyle, linkColor, linkHintByHref)
TokenType.ITALIC_LINK -> renderItalicLink(token, builder, colorScheme, baseTextStyle, linkColor, linkHintByHref)
TokenType.LINK -> renderLink(token, builder, colorScheme, baseTextStyle, linkColor, linkHintByHref)
TokenType.BOLD_LINK -> renderBoldLink(token, builder, colorScheme, baseTextStyle, linkColor, linkHintByHref, linkFontWeight, linkUnderline)
TokenType.ITALIC_LINK -> renderItalicLink(token, builder, colorScheme, baseTextStyle, linkColor, linkHintByHref, linkFontWeight, linkUnderline)
TokenType.LINK -> renderLink(token, builder, colorScheme, baseTextStyle, linkColor, linkHintByHref, linkFontWeight, linkUnderline)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[HIGH] linkFontWeight/linkUnderline are passed to the top-level link renderers but get lost on the nested path. renderList and renderBlockquote (lines 153–154) don't take them, and renderNestedMarkdown calls renderToken again at line 521 without them, so the defaults (null / true) come back. For example, > [Store](https://store.example.com) with --message-concierge-link-underline: "false" and a custom link weight still shows an underlined, weight-400 link. iOS passes linkUnderline through its nested renderers. Could you pass both values through renderList → renderNestedMarkdown → renderToken and renderBlockquote → renderNestedMarkdown → renderToken, and add a renderer test for a link inside a blockquote and a list?

TokenType.CITATION -> renderCitation(token, builder, colorScheme, baseTextStyle)
TokenType.BOLD -> renderBold(token, builder, colorScheme, baseTextStyle)
TokenType.ITALIC -> renderItalic(token, builder, colorScheme, baseTextStyle)
Expand Down Expand Up @@ -203,7 +207,9 @@ internal object MarkdownRenderer {
colorScheme: ColorScheme,
baseTextStyle: TextStyle,
linkColor: Color,
linkHintByHref: Map<String, String> = emptyMap()
linkHintByHref: Map<String, String> = emptyMap(),
linkFontWeight: FontWeight? = null,
linkUnderline: Boolean = true
) {
val (linkText, linkUrl) = token.groups
val styleStart = builder.length
Expand All @@ -212,7 +218,8 @@ internal object MarkdownRenderer {
builder.addStyle(
baseTextStyle.toSpanStyle().copy(
color = linkColor,
textDecoration = TextDecoration.Underline
textDecoration = if (linkUnderline) TextDecoration.Underline else null,
fontWeight = linkFontWeight ?: baseTextStyle.fontWeight
),
styleStart,
builder.length
Expand All @@ -234,7 +241,9 @@ internal object MarkdownRenderer {
colorScheme: ColorScheme,
baseTextStyle: TextStyle,
linkColor: Color,
linkHintByHref: Map<String, String> = emptyMap()
linkHintByHref: Map<String, String> = emptyMap(),
linkFontWeight: FontWeight? = null,
linkUnderline: Boolean = true
) {
val (linkText, linkUrl) = token.groups
val styleStart = builder.length
Expand All @@ -243,8 +252,8 @@ internal object MarkdownRenderer {
builder.addStyle(
baseTextStyle.toSpanStyle().copy(
color = linkColor,
textDecoration = TextDecoration.Underline,
fontWeight = FontWeight.Bold
textDecoration = if (linkUnderline) TextDecoration.Underline else null,
fontWeight = linkFontWeight ?: FontWeight.Bold

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[LOW] With linkFontWeight ?: FontWeight.Bold, a 500 or 600 link weight makes markdown-bold links lighter than the author's bold. Would taking the heavier of the two (maxOf(linkFontWeight ?: FontWeight.Bold, FontWeight.Bold)) be closer to what's intended? Either way, it would be good to match iOS here.

),
styleStart,
builder.length
Expand All @@ -266,7 +275,9 @@ internal object MarkdownRenderer {
colorScheme: ColorScheme,
baseTextStyle: TextStyle,
linkColor: Color,
linkHintByHref: Map<String, String> = emptyMap()
linkHintByHref: Map<String, String> = emptyMap(),
linkFontWeight: FontWeight? = null,
linkUnderline: Boolean = true
) {
val (linkText, linkUrl) = token.groups
val styleStart = builder.length
Expand All @@ -275,7 +286,8 @@ internal object MarkdownRenderer {
builder.addStyle(
baseTextStyle.toSpanStyle().copy(
color = linkColor,
textDecoration = TextDecoration.Underline,
textDecoration = if (linkUnderline) TextDecoration.Underline else null,
fontWeight = linkFontWeight ?: baseTextStyle.fontWeight,
fontStyle = FontStyle.Italic
),
styleStart,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,47 @@ class ThemeParserTest {
assertEquals(14.0, config?.typography?.citationsFontSize)
}

@Test
fun `parseThemeTokens parses message typography keys`() {
val json = """
{
"theme": {
"--message-font-size": "18px",
"--message-font-weight": "600",
"--message-concierge-link-font-weight": "700",
"--message-concierge-link-underline": "false"
}
}
""".trimIndent()

val tokens = ThemeParser.parseThemeTokens(json)
val typography = tokens?.typography

assertNotNull(typography)
assertEquals(18.0, typography?.fontSize)
assertEquals(600, typography?.fontWeight)
assertEquals(700, typography?.linkFontWeight)
assertEquals(false, typography?.linkUnderline)
}

@Test
fun `parseThemeTokens defaults linkUnderline to true when key is missing`() {
val json = """
{
"theme": {
"--message-font-size": "16px"
}
}
""".trimIndent()

val tokens = ThemeParser.parseThemeTokens(json)

assertNotNull(tokens?.typography)
assertEquals(true, tokens?.typography?.linkUnderline)
assertNull(tokens?.typography?.linkFontWeight)
assertNull(tokens?.typography?.fontWeight)
}

@Test
fun `parseThemeJson should handle complex theme with multiple sections`() {
val json = """
Expand Down
Loading