Skip to main content

Overview

MarkdownTheme is the primary struct for configuring the visual appearance of rendered markdown content. It contains nested types for fonts, colors, spacing, and other visual properties.

Declaration

public struct MarkdownTheme: Equatable

Properties

fonts
Fonts
default:"Fonts()"
Font configurations for different text elements in the markdown view. See MarkdownTheme.Fonts for details.
colors
Colors
default:"Colors()"
Color configurations for text, highlights, code blocks, and backgrounds. See MarkdownTheme.Colors for details.
spacings
Spacings
default:"Spacings()"
Spacing configurations for layout and padding. See MarkdownTheme.Spacings for details.
sizes
Sizes
default:"Sizes()"
Size configurations for visual elements like bullets. See MarkdownTheme.Sizes for details.
table
Table
default:"Table()"
Table-specific styling configurations. See MarkdownTheme.Table for details.
image
Image
default:"Image()"
Image-specific styling configurations. See MarkdownTheme.Image for details.

Static Properties

default
MarkdownTheme
The default theme instance with system default values.
codeScale
Double
default:"0.85"
The scale factor applied to code font sizes relative to body text.

Methods

scaleFont(by:)

Scales all fonts in the theme by a predefined scale factor.
mutating func scaleFont(by scale: FontScale)
scale
FontScale
required
The font scale to apply. Options: .tiny, .small, .middle, .large, .huge
Description: Adjusts the font sizes for body, codeInline, bold, italic, code, largeTitle, and title based on the selected scale. Each scale applies an offset to the default font sizes.

align(to:)

Aligns all fonts to a specific point size.
mutating func align(to pointSize: CGFloat)
pointSize
CGFloat
required
The base point size to align fonts to.
Description: Sets the body font to the specified point size and adjusts all other fonts proportionally. Code fonts are scaled by codeScale (0.85).

Nested Types

FontScale

An enumeration defining predefined font scaling options.
public enum FontScale: String, CaseIterable {
    case tiny
    case small
    case middle
    case large
    case huge
}
tiny
FontScale
Applies -4 point offset to default fonts.
small
FontScale
Applies -2 point offset to default fonts.
middle
FontScale
Applies 0 point offset (default size).
large
FontScale
Applies +2 point offset to default fonts.
huge
FontScale
Applies +4 point offset to default fonts.

FontScale Methods

offset
var offset: Int { get }
Returns the point size offset for the scale. scale(_:)
func scale(_ font: PlatformFont) -> PlatformFont
Applies the scale offset to a font, ensuring a minimum size of 4 points.

Initializer

public init()
Creates a new theme with default values for all properties.

Example

var theme = MarkdownTheme.default

// Scale all fonts
theme.scaleFont(by: .large)

// Or align to specific size
theme.align(to: 16)

// Customize colors
theme.colors.body = .label
theme.colors.highlight = .systemBlue

// Customize spacing
theme.spacings.general = 12
theme.spacings.list = 10

Build docs developers (and LLMs) love