Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions Documentation/style-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ Feature toggles and interaction configuration.
| `behavior.citations.defaultLinkIcon` | string \| null | `null` | Same as `phoneIcon`, for links with any other `kind` — including links with no matching `linkHints` entry. |
| `behavior.citations.linkIconStyle.size` | number | `16` | Inline link icon size, in dp. |
| `behavior.citations.linkIconStyle.spacing` | number | `2` | Gap between link text and its icon, in dp. |
| `behavior.citations.linkIconStyle.color` | string | `--message-concierge-link-color`, else primary | Inline link icon tint color (hex). |
| `behavior.citations.linkIconStyle.color` | string | `--message-concierge-link-color`, else `--color-text` | Inline link icon tint color (hex). |

`phoneIcon`/`storeIcon`/`defaultLinkIcon`/`linkIconStyle` only affect links rendered inline within AI message text. The citation list icon (in the expanded sources accordion) is a fixed 14dp size tinted with the citation URL color, and always uses the built-in pop-out icon — only `showLinkIcon` applies to it.

Expand Down Expand Up @@ -723,7 +723,7 @@ Visual styling using CSS-like variable names. All properties in the `theme` obje
| `--message-user-text` | `colors.message.userText` | `String` | `"#000000"` | User message text color (hex) |
| `--message-concierge-background` | `colors.message.conciergeBackground` | `String` | `"#F5F5F5"` | AI message bubble background (hex) |
| `--message-concierge-text` | `colors.message.conciergeText` | `String` | `"#000000"` | AI message text color (hex) |
| `--message-concierge-link-color` | `colors.message.conciergeLink` | `String` | `"#1976D2"` | Link color in AI messages (hex) |
| `--message-concierge-link-color` | `colors.message.conciergeLink` | `String` | `"#1976D2"` | Link color in AI messages (hex): inline link text, expanded citation URLs, and the inline link-icon fallback color. When a theme JSON omits this key, all of these fall back to `--color-text`. With no theme JSON loaded, the built-in palettes use `#0000FF` (light) and `#1E88E5` (dark). |

### Colors - Buttons

Expand Down Expand Up @@ -1522,7 +1522,7 @@ These colors are used internally by composables but cannot be customized in them
| `--message-user-text` | ✅ | User message text color | `ChatMessageItem` |
| `--message-concierge-background` | ✅ | AI message bubble background | `ChatMessageItem` |
| `--message-concierge-text` | ✅ | AI message text color, feedback dialog text, feedback button icons, prompt suggestion chip text/icon fallback, expanded citation list text, chat footer (Sources label and icon) | `ChatMessageItem`, `FeedbackDialog`, `FeedbackButtons`, `PromptSuggestions`, `ExpandedCitations`, `ChatFooter`, `ProductCard` text, `ProductCarousel` switcher color |
| `--message-concierge-link-color` | ✅ | Link color in AI messages; expanded citation list URLs | `ExpandedCitations` (citation URLs); message body links when applied |
| `--message-concierge-link-color` | ✅ | Link color in AI messages; expanded citation list URLs; inline link icon fallback | `MarkdownParser` (message body links), `ExpandedCitations` (citation URLs), `ConciergeResponse` (link icon fallback) |
| `--button-primary-background` | ✅ | Primary button background | `ProductActionButtons` |
| `--button-primary-text` | ✅ | Primary button text | `ProductActionButtons` |
| `--button-primary-hover` | ⚠️ | Parsed but no hover states on Android | - |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,16 @@ package com.adobe.marketing.mobile.concierge.utils.markdown

import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.style.TextDecoration
import com.adobe.marketing.mobile.concierge.ui.theme.ConciergeMessageColors
import com.adobe.marketing.mobile.concierge.ui.theme.ConciergeTheme
import com.adobe.marketing.mobile.concierge.ui.theme.ConciergeThemeColors
import com.adobe.marketing.mobile.concierge.ui.theme.ConciergeThemeConfig
import com.adobe.marketing.mobile.concierge.ui.theme.ConciergeThemeData
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotEquals
import org.junit.Assert.assertNotSame
import org.junit.Assert.assertSame
Expand Down Expand Up @@ -103,4 +110,63 @@ class MarkdownParserComposeTest {
assertNotEquals(firstRender.text, latestRender.text)
}
}

@Test
fun parse_recolorsLinks_whenThemeLinkColorChanges() {
val results = mutableListOf<AnnotatedString>()
val text = "Visit [the store](https://store.example.com)"
val themeState = mutableStateOf(themeWithLinkColor("#FF0000"))

composeTestRule.setContent {
ConciergeTheme(theme = themeState.value) {
val rendered = MarkdownParser.parse(text)
SideEffect { results.add(rendered) }
}
}

composeTestRule.waitForIdle()
composeTestRule.runOnIdle {
assertEquals(Color(0xFFFF0000), linkColorOf(results.last()))
}

composeTestRule.runOnIdle { themeState.value = themeWithLinkColor("#00FF00") }
composeTestRule.waitForIdle()

composeTestRule.runOnIdle {
assertEquals(Color(0xFF00FF00), linkColorOf(results.last()))
}
}

@Test
fun parse_fallsBackToTextColor_whenThemeOmitsLinkColor() {
val results = mutableListOf<AnnotatedString>()
val theme = ConciergeThemeData(
config = ConciergeThemeConfig(
colors = ConciergeThemeColors(primary = "#FF0000", onSurface = "#123456")
),
tokens = null
)

composeTestRule.setContent {
ConciergeTheme(theme = theme) {
val rendered = MarkdownParser.parse("Visit [the store](https://store.example.com)")
SideEffect { results.add(rendered) }
}
}

composeTestRule.waitForIdle()
composeTestRule.runOnIdle {
assertEquals(Color(0xFF123456), linkColorOf(results.last()))
}
}

private fun themeWithLinkColor(hex: String) = ConciergeThemeData(
config = ConciergeThemeConfig(
colors = ConciergeThemeColors(message = ConciergeMessageColors(conciergeLink = hex))
),
tokens = null
)

private fun linkColorOf(rendered: AnnotatedString): Color =
rendered.spanStyles.single { it.item.textDecoration == TextDecoration.Underline }.item.color
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import androidx.compose.ui.unit.dp
import com.adobe.marketing.mobile.concierge.ui.theme.ConciergeCitationsBehavior
import com.adobe.marketing.mobile.concierge.ui.theme.ConciergeStyles
import com.adobe.marketing.mobile.concierge.ui.theme.ConciergeTheme
import com.adobe.marketing.mobile.concierge.ui.theme.toComposeColor
import com.adobe.marketing.mobile.concierge.network.Citation
import com.adobe.marketing.mobile.concierge.network.LinkHint

Expand All @@ -60,7 +59,6 @@ internal fun ConciergeResponse(
) {
val context = LocalContext.current
val style = ConciergeStyles.citationBadgeStyle
val colorScheme = ConciergeTheme.colorScheme

Crossfade(
targetState = text.isEmpty(),
Expand All @@ -82,13 +80,15 @@ internal fun ConciergeResponse(
}
val citationsBehavior = ConciergeTheme.tokens?.behavior?.citations ?: ConciergeCitationsBehavior()

// Compute style values from linkIconStyle, falling back to theme link color then primary
// Compute style values from linkIconStyle, falling back to theme link color then onSurface
val iconStyle = citationsBehavior.linkIconStyle
val iconSize = iconStyle?.size?.dp ?: 16.dp
val iconSpacing = iconStyle?.spacing?.dp ?: 2.dp
val iconColor = iconStyle?.color?.toComposeColor()
?: ConciergeTheme.colors.messageConciergeLink
?: colorScheme.primary
val iconColor = LinkHintUiUtils.resolveLinkIconColor(
iconStyle = iconStyle,
linkColor = ConciergeTheme.colors.messageConciergeLink,
textColor = ConciergeTheme.colors.onSurface
)

// Augment linkHints to cover every URL in the text when showLinkIcon is enabled.
// Non-hint URLs receive kind "default" so they get the default icon asset.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import androidx.core.net.toUri
import com.adobe.marketing.mobile.concierge.ConciergeConstants
import com.adobe.marketing.mobile.concierge.network.LinkHint
import com.adobe.marketing.mobile.concierge.ui.theme.ConciergeCitationsBehavior
import com.adobe.marketing.mobile.concierge.ui.theme.ConciergeLinkIconStyle
import com.adobe.marketing.mobile.concierge.ui.theme.toComposeColor
import com.adobe.marketing.mobile.concierge.utils.markdown.MarkdownRenderer

/**
Expand Down Expand Up @@ -65,6 +67,16 @@ internal object LinkHintUiUtils {
.map { url -> hintsByHref[url] ?: LinkHint(kind = "default", href = url) }
}

/**
* Resolves the tint for inline link icons: [ConciergeLinkIconStyle.color] when it is a valid
* hex color, otherwise [linkColor], otherwise [textColor].
*/
internal fun resolveLinkIconColor(
iconStyle: ConciergeLinkIconStyle?,
linkColor: Color?,
textColor: Color
): Color = iconStyle?.color?.toComposeColor() ?: linkColor ?: textColor

/**
* Creates an inline text content map for link hint icons.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ val DarkConciergeColors = ConciergeColors(
micButtonColor = Color(0xFF6B6B6B),
citationBackground = Color(0xFF6B6B6B),
citationText = Color(0xFFCAC4D0),
messageConciergeLink = Color.Blue,
messageConciergeLink = Color(0xFF1E88E5),
feedbackDialogCheckboxCheckedColor = null,
feedbackDialogCancelButtonColor = Color(0xFF6B6B6B),
feedbackDialogSubmitButtonColor = Color(0xFF6B6B6B),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ internal object MarkdownParser {
val messageBubbleStyle = ConciergeStyles.messageBubbleStyle
val messageTextStyle = messageBubbleStyle.textStyle.copy(color = messageBubbleStyle.botMessageTextColor)
val darkTheme = isSystemInDarkTheme()
val linkColor = ConciergeTheme.colors.messageConciergeLink ?: ConciergeTheme.colors.onSurface

// Memoize the rendered AnnotatedString. Without this, MarkdownRenderer.render() re-runs on
// every recomposition for every visible message, rebuilding the full AnnotatedString. During
Expand All @@ -51,17 +52,18 @@ internal object MarkdownParser {
//
// Keys must be value-comparable for the cache to hold across recompositions: `markdown` and
// `linkHints` cover the content; `messageTextStyle` (TextStyle has structural equality) covers
// typography and text color; `darkTheme` covers the derived `colorScheme`. `colorScheme`
// typography and text color; `linkColor` (Color is a value class) covers the link color;
// `darkTheme` covers the derived `colorScheme`. `colorScheme`
// 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, darkTheme) {
return remember(markdown, linkHints, messageTextStyle, linkColor, darkTheme) {
Log.debug(
ConciergeConstants.EXTENSION_NAME,
TAG,
"Parsed ${tokens.size} tokens, starting rendering."
)
MarkdownRenderer.render(markdown, tokens, colorScheme, messageTextStyle, linkHints)
MarkdownRenderer.render(markdown, tokens, colorScheme, messageTextStyle, linkHints, linkColor)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,17 @@ internal object MarkdownRenderer {
* @param tokens The list of [MarkdownToken]s to render.
* @param colorScheme The Material Design color scheme.
* @param baseTextStyle The base text style to apply to regular text.
* @param linkHints Link hints used to append icons after matching links.
* @param linkColor Color applied to link text. Falls back to [ColorScheme.onSurface] when unspecified.
* @return An [AnnotatedString] with the appropriate styling applied.
*/
fun render(
markdown: String,
tokens: List<MarkdownToken>,
colorScheme: ColorScheme,
baseTextStyle: TextStyle,
linkHints: List<LinkHint> = emptyList()
linkHints: List<LinkHint> = emptyList(),
linkColor: Color = Color.Unspecified
): AnnotatedString {
Log.debug(
ConciergeConstants.EXTENSION_NAME,
Expand All @@ -80,14 +83,15 @@ internal object MarkdownRenderer {
)

val linkHintByHref: Map<String, String> = linkHints.associate { it.href to it.kind }
val resolvedLinkColor = linkColor.takeIf { it != Color.Unspecified } ?: colorScheme.onSurface
val builder = AnnotatedString.Builder()
var currentIndex = 0

tokens.forEach { token ->
if (token.start < currentIndex) return@forEach

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

Expand Down Expand Up @@ -129,20 +133,21 @@ internal object MarkdownRenderer {
builder: AnnotatedString.Builder,
colorScheme: ColorScheme,
baseTextStyle: TextStyle,
linkColor: Color,
linkHintByHref: Map<String, String> = emptyMap()
) {
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, linkHintByHref)
TokenType.ITALIC_LINK -> renderItalicLink(token, builder, colorScheme, baseTextStyle, linkHintByHref)
TokenType.LINK -> renderLink(token, builder, colorScheme, baseTextStyle, linkHintByHref)
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.CITATION -> renderCitation(token, builder, colorScheme, baseTextStyle)
TokenType.BOLD -> renderBold(token, builder, colorScheme, baseTextStyle)
TokenType.ITALIC -> renderItalic(token, builder, colorScheme, baseTextStyle)
TokenType.HEADING -> renderHeading(token, builder, colorScheme, baseTextStyle)
TokenType.LIST -> renderList(token, builder, colorScheme, baseTextStyle, linkHintByHref)
TokenType.BLOCKQUOTE -> renderBlockquote(token, builder, colorScheme, baseTextStyle, linkHintByHref)
TokenType.LIST -> renderList(token, builder, colorScheme, baseTextStyle, linkColor, linkHintByHref)
TokenType.BLOCKQUOTE -> renderBlockquote(token, builder, colorScheme, baseTextStyle, linkColor, linkHintByHref)
}
}

Expand Down Expand Up @@ -197,6 +202,7 @@ internal object MarkdownRenderer {
builder: AnnotatedString.Builder,
colorScheme: ColorScheme,
baseTextStyle: TextStyle,
linkColor: Color,
linkHintByHref: Map<String, String> = emptyMap()
) {
val (linkText, linkUrl) = token.groups
Expand All @@ -205,7 +211,7 @@ internal object MarkdownRenderer {
builder.append(linkText)
builder.addStyle(
baseTextStyle.toSpanStyle().copy(
color = colorScheme.primary,
color = linkColor,
textDecoration = TextDecoration.Underline
),
styleStart,
Expand All @@ -227,6 +233,7 @@ internal object MarkdownRenderer {
builder: AnnotatedString.Builder,
colorScheme: ColorScheme,
baseTextStyle: TextStyle,
linkColor: Color,
linkHintByHref: Map<String, String> = emptyMap()
) {
val (linkText, linkUrl) = token.groups
Expand All @@ -235,7 +242,7 @@ internal object MarkdownRenderer {
builder.append(linkText)
builder.addStyle(
baseTextStyle.toSpanStyle().copy(
color = colorScheme.primary,
color = linkColor,
textDecoration = TextDecoration.Underline,
fontWeight = FontWeight.Bold
),
Expand All @@ -258,6 +265,7 @@ internal object MarkdownRenderer {
builder: AnnotatedString.Builder,
colorScheme: ColorScheme,
baseTextStyle: TextStyle,
linkColor: Color,
linkHintByHref: Map<String, String> = emptyMap()
) {
val (linkText, linkUrl) = token.groups
Expand All @@ -266,7 +274,7 @@ internal object MarkdownRenderer {
builder.append(linkText)
builder.addStyle(
baseTextStyle.toSpanStyle().copy(
color = colorScheme.primary,
color = linkColor,
textDecoration = TextDecoration.Underline,
fontStyle = FontStyle.Italic
),
Expand Down Expand Up @@ -413,6 +421,7 @@ internal object MarkdownRenderer {
builder: AnnotatedString.Builder,
colorScheme: ColorScheme,
baseTextStyle: TextStyle,
linkColor: Color,
linkHintByHref: Map<String, String> = emptyMap()
) {
val listItem = token.groups[0]
Expand All @@ -426,20 +435,21 @@ internal object MarkdownRenderer {
builder.append("• ")
}

renderNestedMarkdown(listItem, builder, colorScheme, baseTextStyle, linkHintByHref)
renderNestedMarkdown(listItem, builder, colorScheme, baseTextStyle, linkColor, linkHintByHref)
}

private fun renderBlockquote(
token: MarkdownToken,
builder: AnnotatedString.Builder,
colorScheme: ColorScheme,
baseTextStyle: TextStyle,
linkColor: Color,
linkHintByHref: Map<String, String> = emptyMap()
) {
val quoteText = token.groups[0]

val contentColor = baseTextStyle.color.takeIf { it != Color.Unspecified } ?: colorScheme.onSurface
renderNestedMarkdown(quoteText, builder, colorScheme, baseTextStyle, linkHintByHref) { text, _, _ ->
renderNestedMarkdown(quoteText, builder, colorScheme, baseTextStyle, linkColor, linkHintByHref) { text, _, _ ->
val styleStart = builder.length
builder.append(text)
builder.addStyle(
Expand All @@ -460,13 +470,15 @@ internal object MarkdownRenderer {
* @param content The content to render
* @param builder The AnnotatedString builder
* @param colorScheme The Material Design color scheme
* @param linkColor Color applied to link text
* @param textRenderer Optional function to render plain text with custom styling
*/
private fun renderNestedMarkdown(
content: String,
builder: AnnotatedString.Builder,
colorScheme: ColorScheme,
baseTextStyle: TextStyle,
linkColor: Color,
linkHintByHref: Map<String, String> = emptyMap(),
textRenderer: ((String, Int, Int) -> Unit)? = null
) {
Expand Down Expand Up @@ -494,7 +506,7 @@ internal object MarkdownRenderer {
}

// Render the nested token
renderToken(nestedToken, builder, colorScheme, baseTextStyle, linkHintByHref)
renderToken(nestedToken, builder, colorScheme, baseTextStyle, linkColor, linkHintByHref)
currentIndex = nestedToken.end
}

Expand Down
Loading
Loading