Guide

Getting started

Add the package and render a static document or a streaming transcript.

SDK on GitHub ↗

Requirements

Swift 6.3 or later, on macOS 13, iOS/iPadOS 16, or visionOS 1. The SDK is delivered as XCFrameworks with public Swift interfaces through Swift Package Manager.

Add the package

In Xcode, choose File → Add Package Dependencies and enter the repository URL:

text
https://github.com/mikhutchinson/siriusmarkdown-commercial.git

Select version 0.7.23 or later, then add the SiriusMarkdown product to your app target. It includes the rendering, streaming, and interaction APIs most apps need.

Render a document

Append text to a stream, call finish(), prepare a snapshot with a preset, and pass the result to a view.

swift
import SwiftUI
import SiriusMarkdown

var stream = MarkdownStream()
stream.append("# Hello\n\nStreaming **Markdown** with $E = mc^2$.")
stream.finish()

let configuration = MarkdownRendererConfiguration.document
let prepared = configuration.prepare(snapshot: stream.snapshot())

MarkdownDocumentView(preparedSnapshot: prepared, configuration: configuration)

For anything longer than a few paragraphs, prepare off the main thread and then publish the result:

swift
let snapshot = stream.snapshot()
let prepared = await Task.detached {
    configuration.prepare(snapshot: snapshot)
}.value

Render a streaming transcript

MarkdownRenderSession manages a streaming reply for you. Append text as it arrives, and the session publishes useful prepared prefixes while input continues, reusing completed content. Call session.finish() when the reply ends.

Observe the session directly so asynchronous preparation updates the view:

swift
struct TranscriptView: View {
    @ObservedObject var session: MarkdownRenderSession

    var body: some View {
        ScrollView {
            StreamingMarkdownView(
                preparedSnapshot: session.preparedSnapshot,
                configuration: session.configuration
            )
        }
    }
}

Keep the session alive in your host, and call session.append(chunk) on the main actor as text arrives. Use @StateObject when a view creates and owns its session.

When copying must match the displayed prefix, observe session.presentation and bind its source access to a configuration retained by your host. The streaming guide explains how to keep rendering and copy on the same revision.

To insert your own view between messages, such as a tool result or an attachment, call session.appendHostBoundary() first. That seals the Markdown before the insertion, and the snapshot's items then list blocks and boundaries in source order.

What works by default

  • Inline, display, and table-cell math, typeset by DefaultMarkdownMathRenderer.
  • Sixteen Mermaid diagram types, each available as light and dark PDF, SVG, ASCII, and an accessibility summary.
  • Code highlighting for common languages, and plain text for unlabeled or unrecognized code blocks.
  • Selection across blocks, exact Markdown copy, rich clipboard formats where available, Find, and links to headings.
  • Safe defaults: only http, https, mailto, and relative links; sanitized HTML with active content removed; anonymous public HTTPS images with bounded loading.

Shipping math fonts

Math fonts live inside SiriusMarkdownSupport.framework. Swift Package Manager includes and embeds the framework automatically. If you manually assemble an app, preserve all required frameworks and their resources. If fonts are unavailable, math is shown as source text and the mathFallbackCount diagnostics counter goes up.

The view initializers that take a snapshot: directly still exist but are deprecated. Use the prepared-snapshot initializers so highlighting, math, and layout preparation are complete.

Explore the API

The API reference covers SDK types, members and SiriusMarkdown protocol defaults. Start with MarkdownDocumentView for a scrollable reader, or StreamingMarkdownView for content inside your own scroll container.

These views also support standard SwiftUI modifiers. Their reference pages link to Apple’s documentation for that inherited behavior. SiriusMarkdown’s .markdown namespace remains documented with the SDK.

Native captureOpen original ↗
Native document capture