SwiftUI component for rendering streaming Markdown and KaTeX in chat-style apps on iOS 18+ and macOS 15+.
Add the package in your project’s Package.swift
:
.package(url: "https://github.com/ronaldmannak/PicoMarkdownView.git", branch: "main")
Then add PicoMarkdownView
to the target dependencies that require it.
import PicoMarkdownView
@StateObject private var stream = PicoMarkdownStream()
var body: some View {
PicoMarkdownView(stream: stream)
}
func appendChunk(_ markdown: String) {
Task { await stream.append(markdown: markdown) }
}
PicoMarkdownStream
performs incremental parsing. Feed it new Markdown as it arrives (for example from an LLM streaming response). The view maintains continuous selection and reuses layout via a shared NSTextStorage
/ TextKit 2 host under the hood.
let config = PicoMarkdownViewConfiguration(
backgroundColor: .clear,
contentInsets: EdgeInsets(top: 12, leading: 16, bottom: 12, trailing: 16),
isSelectable: true,
isScrollEnabled: false
)
PicoMarkdownView(stream: stream, configuration: config)
Task {
await stream.reset(markdown: "")
}
Run the bundled tests to exercise streaming and table rendering:
swift test