Skip to main content

Overview

MarkdownTheme.Colors defines the color scheme used for rendering markdown content. It provides customization for text colors, highlights, code blocks, and interactive elements.

Declaration

public struct Colors: Equatable

Properties

Text Colors

body
UIColor / NSColor
The color used for body text.Default (iOS/visionOS): UIColor.label (adapts to light/dark mode)Default (macOS): NSColor.labelColor (adapts to light/dark mode)
emphasis
UIColor / NSColor
The color used for emphasized text (italic, strong emphasis).Default: Accent color from asset catalog, falls back to system orange.Lookup order: AccentColoraccentColor.systemOrange
highlight
UIColor / NSColor
The color used for links and highlighted elements.Default: Accent color from asset catalog, falls back to system orange.Lookup order: AccentColoraccentColor.systemOrange

Code Colors

code
UIColor / NSColor
The text color used for code blocks and inline code.Default (iOS/visionOS): UIColor.labelDefault (macOS): NSColor.labelColor
codeBackground
UIColor / NSColor
The background color for code blocks and inline code.Default: UIColor.gray.withAlphaComponent(0.25) / NSColor.gray.withAlphaComponent(0.25)Provides a subtle gray background to distinguish code from regular text.

Selection Colors

selectionBackground
UIColor? / NSColor?
The background color for selected text. Optional.Default: Accent color with 20% opacity.Lookup order: AccentColoraccentColor.systemOrange, then applies .withAlphaComponent(0.2)Set to nil to use the system default selection color.

Platform Types

  • iOS/visionOS: Uses UIColor from UIKit
  • macOS: Uses NSColor from AppKit

Example

var theme = MarkdownTheme()

// Customize text colors
theme.colors.body = .label
theme.colors.emphasis = .systemRed

// Customize link color
theme.colors.highlight = .systemBlue

// Customize code appearance
theme.colors.code = .systemGreen
theme.colors.codeBackground = UIColor.systemGray6

// Customize selection
theme.colors.selectionBackground = UIColor.systemBlue.withAlphaComponent(0.3)

// Disable custom selection color
theme.colors.selectionBackground = nil

Dark Mode Support

All default colors use semantic system colors that automatically adapt to light and dark mode:
  • UIColor.label / NSColor.labelColor - Primary text color
  • UIColor.gray / NSColor.gray - Neutral gray
  • UIColor.systemOrange - Accent fallback color
For custom colors, consider using system colors or asset catalog colors with appearance variants.

Accent Color Resolution

The highlight and emphasis properties attempt to use your app’s accent color:
  1. First checks for AccentColor in the asset catalog
  2. Falls back to accentColor (lowercase)
  3. Finally falls back to .systemOrange
To customize the default accent, add an AccentColor to your asset catalog.

Build docs developers (and LLMs) love