SwiftStreamingMarkdown

作者 microsoft已验证

A performant markdown library for iOS & macOS that supports streaming

338
Stars
40
Forks
Swift
语言
2026/8/23
添加时间

⚠️ 第三方软件声明

本 Skill 为第三方开源软件,独立托管于 GitHub。SkillTip 仅为信息目录,不控制或维护底层仓库。所显示的安全检查为自动化且范围有限,安装前请自行审查源码。

阅读服务条款

安装

添加到你的 Claude Code skills 目录:

# Add to your Claude Code skills
git clone https://github.com/microsoft/SwiftStreamingMarkdown

快速入门

使用 SwiftStreamingMarkdown 等 Skills 的指南。

安全报告

已验证

上次扫描:—

{
  "status": "PASSED",
  "issues": []
}

README.md

SwiftStreamingMarkdown

CI Swift 5.9 iOS 16+ macOS 14+ SwiftPM License: MIT

An iOS and macOS 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

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

Table

LaTeX

Image

image-demo Large

Customization

Inline citation

Inline Citation

Code block

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

  • Headings (#######)
  • Paragraphs with soft and hard line breaks
  • Images (![alt](https://raw.githubusercontent.com/microsoft/SwiftStreamingMarkdown/main/url)) — block-level, opt-in via the experimental ImageConfig (remote-allowlist, asset-catalog, and bundled-resource sources; tap to open the built-in fullscreen viewer)
  • Bold, italic, bold-italic, strikethrough
  • Inline code
  • Inline links
  • Fenced code blocks with language tag
  • Block quotes (with nested inlines, lists, and citations)
  • Ordered lists
  • Unordered lists (with nesting)
  • Task lists (- [ ] / - [x]), display-only
  • Thematic breaks (---)
  • Tables with :---, :---:, ---: column alignment
  • Inline LaTeX math via \( … \)
  • Display LaTeX math via $$ … $$
  • Inline citation pills

Not yet supported

  • Footnotes ([^1])
  • Highlight (==text==), superscript (^x^), subscript (~x~)
  • Raw HTML (<details>, <kbd>, <aside>, …) — 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

profiling-streaming

Markdown library without streaming support

profiling-streaming-comparison

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 approximately 1 MB to your app's App Store download size. The increase comes from the rendering engine and its dependencies (swift-markdown, cmark-gfm, iosMath for LaTeX, HighlightSwift for code syntax highlighting) and bundled resources (math font, syntax-highlighting theme). Actual size varies with 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`.

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

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

Listening for events

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.

Sample app

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.

Development

Run make help to see the repo's common development commands. The most useful targets are:

CommandPurpose
make dev-setupVerify required local tools such as Xcode, SwiftLint, and XcodeGen; warn about optional snapshot diff helpers ImageMagick and diff-image.
make projectResolve Swift package dependencies and open the package in Xcode.
make generate-sample-projectGenerate the sample app project with XcodeGen.
make sample-projectGenerate and open the sample app project in Xcode.
make lintRun swiftlint --strict.
make testRun the package unit tests with xcodebuild.
make build-sampleGenerate and build the sample app.
make ciRun lint, tests, and the sample-app build.
make clocCount code with cloc --vcs=git.

Contributing

Contributions are welcome! Bug reports and feature requests go through the issue templates. See CONTRIBUTING.md for local setup, code style, and the pull-request process.

This project follows the Microsoft Open Source Code of Conduct.

Security

Please follow the responsible-disclosure process described in SECURITY.md. Do not file security issues publicly.

License

SwiftStreamingMarkdown is released under the MIT License. Dependencies are declared in Package.swift; each upstream ships its own license terms via Swift Package Manager.

常见问题

What is SwiftStreamingMarkdown?

SwiftStreamingMarkdown is an open-source ai agents skill for AI coding assistants such as Claude Code, Codex CLI, and ChatGPT, built by microsoft. A performant markdown library for iOS & macOS that supports streaming. It has 338 GitHub stars.

Is SwiftStreamingMarkdown safe to use?

Yes. SwiftStreamingMarkdown passed SkillsLLM's automated security scan — a dependency vulnerability audit plus prompt-injection heuristics — with no high-severity issues. You can read the full report in the Security Report section on this page.

How do I install SwiftStreamingMarkdown?

Clone the repository with "git clone https://github.com/microsoft/SwiftStreamingMarkdown" and add it to your Claude Code skills directory (see the Installation section above).

What programming language is SwiftStreamingMarkdown written in?

SwiftStreamingMarkdown is primarily written in Swift. It is open-source under microsoft on GitHub, so you can review or fork the full source.

Are there alternatives to SwiftStreamingMarkdown?

Yes. SkillsLLM lists many other AI Agents skills you can browse and compare side by side. Open the AI Agents category from the badge at the top of this page, or use the Related Skills and comparison links further down to weigh SwiftStreamingMarkdown against similar tools.

评论 (0)

暂无评论,成为第一个分享想法的人!

ECC

by affaan-m

10

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

242,21936,702JavaScript
AI 智能体ai-agentsanthropicclaude-code
查看详情
15

An agentic skills framework & software development methodology that works.

234,96620,863Shell
AI 智能体ai-agentsbrainstorming
查看详情

hermes-agent

by NousResearch

10

The agent that grows with you

234,43747,175Python
AI 智能体ai-agentsagent-orchestration
查看详情

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

185,94028,768JavaScript
AI 智能体ai-agentsanthropicclaude-code
查看详情

cc-switch

by farion1231

3

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode, OpenClaw, Grok Build & Hermes Agent. Only official website: ccswitch.io

128,8688,826Rust
AI 智能体claude-codeai-tools
查看详情

claude-code

by anthropics

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

120,03119,897Shell
AI 智能体
查看详情

开发者还喜欢

基于喜欢此 Skill 的开发者投票和收藏

ECC

by affaan-m

10

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

242,21936,702JavaScript
AI 智能体ai-agentsanthropicclaude-code
查看详情
15

An agentic skills framework & software development methodology that works.

234,96620,863Shell
AI 智能体ai-agentsbrainstorming
查看详情

hermes-agent

by NousResearch

10

The agent that grows with you

234,43747,175Python
AI 智能体ai-agentsagent-orchestration
查看详情

n8n

by n8n-io

12

Fair-code workflow automation platform with native AI capabilities. Combine visual building with custom code, self-host or cloud, 400+ integrations.

201,88160,308TypeScript
MCP 服务器apisai-tools
查看详情

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

185,94028,768JavaScript
AI 智能体ai-agentsanthropicclaude-code
查看详情

cc-switch

by farion1231

3

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode, OpenClaw, Grok Build & Hermes Agent. Only official website: ccswitch.io

128,8688,826Rust
AI 智能体claude-codeai-tools
查看详情