RepoMicrosoftMicrosoftpublished May 22, 2026seen 1w

microsoft/SwiftStreamingMarkdown

Swift

Open original ↗

Captured source

source ↗

microsoft/SwiftStreamingMarkdown

Description: A performant markdown library for iOS that supports streaming

Language: Swift

License: MIT

Stars: 188

Forks: 12

Open issues: 3

Created: 2026-05-22T22:37:08Z

Pushed: 2026-06-19T03:10:03Z

Default branch: main

Fork: no

Archived: no

README:

SwiftStreamingMarkdown

![CI](https://github.com/microsoft/SwiftStreamingMarkdown/actions/workflows/ci.yml)

An iOS Markdown renderer that offers smooth streaming experiences.

  • ⚡ Smooth, high-performance streaming transitions for newly received text
  • 🧮 Native inline and block LaTeX math rendering
  • 🔗 Inline citation UI for source-grounded LLM responses
  • 🎨 Highly configurable typography, theming, and iOS context menus
  • 📊 Built-in hooks for analytics and interaction tracking

Catalog

  • [Demos](#demos)
  • [Markdown support](#markdown-support)
  • [Supported](#supported)
  • [Not yet supported](#not-yet-supported)
  • [Streaming Performance](#streaming-performance)
  • [Installation](#installation)
  • [Xcode](#xcode)
  • [Package.swift](#packageswift)
  • [Binary Size](#binary-size)
  • [Quick start](#quick-start)
  • [Streaming usage](#streaming-usage)
  • [Customizing the theme](#customizing-the-theme)
  • [Listening for events](#listening-for-events)
  • [Sample app](#sample-app)
  • [Development](#development)
  • [Contributing](#contributing)
  • [Security](#security)
  • [License](#license)

Demos

Here are a few demos to help you quickly understand this library's capabilities. More can be found in the sample app.

Table

LaTeX

Customization

Inline citation

Code block

Markdown support

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.

Supported

  • [x] Headings (#######)
  • [x] Paragraphs with soft and hard line breaks
  • [x] Bold, *italic*, *bold-italic*, ~~strikethrough~~
  • [x] Inline code
  • [x] Inline links
  • [x] Fenced code blocks with language tag
  • [x] Block quotes (with nested inlines, lists, and citations)
  • [x] Ordered lists
  • [x] Unordered lists (with nesting)
  • [x] Thematic breaks (---)
  • [x] Tables with :---, :---:, ---: column alignment
  • [x] Inline LaTeX math via \( … \)
  • [x] Display LaTeX math via $$ … $$
  • [x] Inline citation pills

Not yet supported

  • [ ] Images (![alt](url)) — alt text only
  • [ ] Task lists (- [ ] / - [x])
  • [ ] Footnotes ([^1])
  • [ ] Highlight (==text==), superscript (^x^), subscript (~x~)
  • [ ] Raw HTML (`, , `, …) — kept inline as text
  • [ ] GitHub alerts (> [!NOTE]) — rendered as plain block quotes
  • [ ] Container directives (::: warning … :::) and admonitions (!!! note)
  • [ ] Mermaid / PlantUML diagrams — rendered as fenced code

The bundled Kitchen Sink demonstration in the sample app exercises every item above so you can verify the fallback behavior on-device.

Streaming Performance

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

Markdown library without streaming support

Installation

SwiftStreamingMarkdown is distributed exclusively as a Swift Package.

Xcode

1. Choose File ▸ Add Package Dependencies… 2. Enter https://github.com/microsoft/SwiftStreamingMarkdown 3. Select the version rule you want (e.g. *Up to next minor*) and add the SwiftStreamingMarkdown 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")
]
)

Binary Size

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.

Quick start

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`.

print("Hello, world!")

""")
.padding()
}
}
}

Streaming usage

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 { ... }
}

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](Examples/SwiftStreamingMarkdownSample) demonstrates chunked streaming end-to-end with adjustable chunk size and interval, plus auto-scroll wired through a MarkdownListener.

Customizing the theme

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:...

Excerpt shown — open the source for the full document.

Notability

notability 4.0/10

Utility library, moderate stars.