by microsoft
A performant markdown library for iOS that supports streaming
# Add to your Claude Code skills
git clone https://github.com/microsoft/SwiftStreamingMarkdownGuides for using ai agents skills like SwiftStreamingMarkdown.
Last scanned: 6/14/2026
{
"issues": [],
"status": "PASSED",
"scannedAt": "2026-06-14T08:16:37.067Z",
"npmAuditRan": true,
"pipAuditRan": true,
"promptInjectionRan": true
}No comments yet. Be the first to share your thoughts!
30 days in the Featured rail · terms & refunds
An iOS Markdown renderer that offers smooth streaming experiences.
Here are a few demos to help you quickly understand this library's capabilities. More can be found in the sample app.
The renderer targets the subset of CommonMark + GitHub-flavored Markdown that LLM responses actually emit. Unsupported syntax degrades to readable text so streamed responses never break.
# … ######)Inline code---):---, :---:, ---: column alignment\( … \)$$ … $$) — alt text only- [ ] / - [x])[^1])==text==), superscript (^x^), subscript (~x~)<details>, <kbd>, <aside>, …) — kept inline as text> [!NOTE]) — rendered as plain block quotes::: warning … :::) and admonitions (!!! note)The bundled Kitchen Sink demonstration in the sample app exercises every item above so you can verify the fallback behavior on-device.
SwiftStreamingMarkdown includes built-in animations for streaming content as new text arrives. It is designed to keep rendering smooth while minimizing main-thread work. The chart below compares its performance against popular Markdown libraries that do not provide built-in streaming support.
Profiling was performed on an iPhone XS using the sample app while continuously streaming content and scrolling. Even under this demanding workload on older hardware, SwiftStreamingMarkdown maintains smooth rendering without noticeable UI stalls.
SwiftStreamingMarkdown is distributed exclusively as a Swift Package.
https://github.com/microsoft/SwiftStreamingMarkdownSwiftStreamingMarkdown product to your app target.Package.swift.package(url: "https://github.com/microsoft/SwiftStreamingMarkdown", from: "0.1.0"),
.target(
name: "MyApp",
dependencies: [
.product(name: "SwiftStreamingMarkdown", package: "SwiftStreamingMarkdown")
]
)
Integrating SwiftStreamingMarkdown adds roughly 3 MB to your app's App Store download size. The increase comes from the rendering engine and its dependencies (e.g. swift-markdown, cmark-gfm, iosMath for LaTeX, HighlightSwift for code syntax highlighting) and bundled resources such as math fonts and the syntax-highlighting runtime. Actual size depends on your app's architecture slices and App Store compression.
The simplest entry point is MarkdownView, which parses and renders a static
string of Markdown using the default theme:
import SwiftUI
import SwiftStreamingMarkdown
struct ContentView: View {
var body: some View {
ScrollView {
MarkdownView(text: """
# Hello, **world!**
SwiftStreamingMarkdown supports tables, lists, code blocks, and
inline `code`.
```swift
print("Hello, world!")
```
""")
.padding()
}
}
}
For chat-style UIs that grow the Markdown source over time, use
StreamedMarkdownView. It takes a StreamedMarkdownSource whose text
property yields progressively larger snapshots of the Markdown source (each
emission is the full source so far, not a delta) and incrementally parses
and renders them as they arrive.
import SwiftUI
import SwiftStreamingMarkdown
class ChatResponseSource: ObservableObject, StreamedMarkdownSource {
var text: AsyncStream<String> { ... }
}
struct ChatBubble: View {
@EnvironmentObject var source: ChatResponseSource
var body: some View {
StreamedMarkdownView(source: source)
}
}
If you'd rather drive DocumentView directly, parse each snapshot with
MarkdownParser.parse(text:config:) and feed the resulting
RenderableDocument into your view yourself.
The bundled sample app demonstrates
chunked streaming end-to-end with adjustable chunk size and interval, plus
auto-scroll wired through a MarkdownListener.
MarkdownRenderConfig is the single source of truth for styling. Build one
by composing the withXxx helpers on .default:
let config = MarkdownRenderConfig.default
.withShouldAnimateText(value: true)
.withHeadingStyle(value: MarkdownRenderConfig.defaultHeadingStyle)
.withParagraphStyle(value: MarkdownRenderConfig.defaultParagraphStyle)
For finer control, construct MarkdownRenderConfig directly to override the
inline, paragraph, heading, list, table, and citation styles in one place.
Conform to MarkdownListener to receive notifications whenever the renderer
draws or the user interacts with rendered content (table copy/download taps,
context-menu lifecycle, etc.):
final class AnalyticsListener: MarkdownListener {
func onRender(markdown: RenderableDocument) async { /* ... */ }
func onTableCopyTap(content: String) async { /* ... */ }
func onTableDownloadTap(content: String) async { /* ... */ }
func onContextMenuAppear(id: String, selectedContent: String) async { /* ... */ }
func onContextMenuTap(id: String, selectedContent: String) async { /* ... */ }
}
MarkdownView(text: source, listener: AnalyticsListener())
The listener is propagated through the SwiftUI environment, so deeply nested rendered subviews observe the same hooks.
A SwiftUI sample app lives in
Examples/SwiftStreamingMarkdownSample.
It includes a streaming demonstration with adjustable chunk size and interval,
a settings screen, and a logging MarkdownListener implementation. The sample
Xcode project is generated from Examples/SwiftStreamingMarkdownSample/project.yml;
run make sample-project to generate and open it in Xcode.
Run make help to see the repo's common development commands. The most useful
targets are:
| Command | Purpose |
|---|---|
make dev-setup |
Verify local tools such as Xcode, SwiftLint, XcodeGen, cloc, ImageMagick, and diff-image. |
make project |
Resolve Swift package dependencies and open |