Swift Markdown Kit · DOCS

Theming & Syntax

Theming & Syntax

Themes

A named preset plus per-token overrides. theme controls light/dark mode; markdownTheme controls the preset and its tokens. Both apply at runtime.

let theme = MarkdownTheme.github
    .linkColor(light: .systemIndigo, dark: .systemTeal)
    .codeCornerRadius(8)
    .headingSize(level: 1, em: 2.2)

let options = MarkdownRenderOptions(
    theme: .auto,            // light / dark / auto
    markdownTheme: theme     // preset + token overrides
)

MarkdownRenderView(markdown: "# Hello", options: options)

Changing the baseline appearance (the default CSS) requires rebuilding the renderer and repackaging the framework. Runtime preset selection and per-token overrides do not.

Custom inline syntax

Register declarative inline extensions — no code crosses the bridge. Each match renders as a fully escaped .md-ext-{name} span and reports taps as events.

let options = MarkdownRenderOptions(
    extensions: [
        .mention(),    // @handle
        .ticker(),     // $AAPL (uppercase only, "$5" is untouched)
        .wikilink(),   // [[Page]]
        .prefix(name: "issue", trigger: "#", body: .upperDigit, action: "issue"),
        .delimiter(name: "spoiler", open: "||", close: "||", action: "spoiler")
    ]
)

Two modes: prefix (a trigger character plus a restricted body character class) and delimiter (open…close). Captured values are HTML-escaped and identifier-sanitised by the core. Styling goes through the same theme tokens — each extension exposes --md-ext-{name}-color, -bg, -radius, -padding, -weight and -decoration.