Back to OSS
Swift Package UI / SwiftUI

swift-markdown-view

DesignSystem 統合とシンタックスハイライトを備えた SwiftUI ネイティブな Markdown レンダリング

Swift
swiftuimarkdownsyntax-highlighting

SwiftMarkdownView

English | 日本語

A SwiftUI-native Markdown rendering library. Integrates with DesignSystem for beautiful Markdown display.

Swift 6.0+ iOS 17+ macOS 14+ License

Features

  • SwiftUI Native: High-performance rendering using NSTextStorage + TextKit 2
  • DesignSystem Integration: Seamless integration with ColorPalette, Typography, and Spacing
  • Optional Syntax Highlighting: 50+ languages via separate HighlightJS module
  • Rich Element Support: Tables, task lists, images, Mermaid diagrams, math (LaTeX), and more
  • Customizable: Style configuration through environment values

Quick Start

import SwiftUI
import SwiftMarkdownView

struct ContentView: View {
    var body: some View {
        MarkdownView("""
        # Hello, Markdown!

        This is a **bold** and *italic* text.

        ```swift
        let greeting = "Hello, World!"
        print(greeting)
        ```

        - [x] Task completed
        - [ ] Task pending
        """)
    }
}

Installation

Swift Package Manager

Add to your Package.swift:

dependencies: [
    .package(url: "https://github.com/no-problem-dev/swift-markdown-view.git", from: "1.4.3")
]

Add to your target:

.target(
    name: "YourTarget",
    dependencies: [
        .product(name: "SwiftMarkdownView", package: "swift-markdown-view"),
        // For syntax highlighting (optional)
        .product(name: "SwiftMarkdownViewHighlightJS", package: "swift-markdown-view")
    ]
)

Supported Elements

Block Elements

Element Markdown Notes
Headings # H1 ~ ###### H6 Typography integration
Paragraphs text
Code Blocks ```swift ``` Optional highlighting
Asides > Note: text 24 kinds + custom
Mermaid ```mermaid ``` iOS 26+ recommended
Math $$...$$ / ```math ``` LaTeX display math
Unordered Lists - item Nested supported
Ordered Lists 1. item Nested supported
Task Lists - [x] done
Tables | col | Alignment supported
Thematic Breaks ---

Inline Elements

Element Markdown
Emphasis (italic) *text*
Strong (bold) **text**
Inline Code `code`
Links [text](url)
Images ![alt](url)
Strikethrough ~~text~~
Inline Math $...$ / \(...\)

Syntax Highlighting

Default Behavior

By default, code blocks are displayed without highlighting.

HighlightJS Highlighting

To enable syntax highlighting with 50+ languages, use the optional module:

import SwiftMarkdownView
import SwiftMarkdownViewHighlightJS

// Recommended: Adaptive highlighting (auto light/dark mode)
MarkdownView(source)
    .adaptiveSyntaxHighlighting()

// With specific theme
MarkdownView(source)
    .adaptiveSyntaxHighlighting(theme: .github)

// Manual configuration
MarkdownView(source)
    .syntaxHighlighter(
        HighlightJSSyntaxHighlighter(theme: .atomOne, colorMode: .dark)
    )

Available Themes: .a11y (accessibility recommended), .xcode, .github, .atomOne, .solarized, .tokyoNight

Custom Highlighter

Implement your own highlighting logic:

struct MyHighlighter: SyntaxHighlighter {
    func highlight(_ code: String, language: String?) async throws -> AttributedString {
        var result = AttributedString(code)
        // Custom implementation
        return result
    }
}

MarkdownView(source)
    .syntaxHighlighter(MyHighlighter())

Asides (Callouts)

Blockquotes are interpreted as callouts such as Note, Warning, and Tip.

MarkdownView("""
> Note: This is supplementary information.

> Warning: This requires attention.

> Tip: Here's a helpful tip.
""")

Supported Kinds: Note, Tip, Important, Warning, Experiment, Attention, Bug, ToDo, SeeAlso, Throws, and 24 more + custom

Mermaid Diagrams

Code blocks with mermaid language are rendered as diagrams.

MarkdownView("""
```mermaid
graph TD
    A[Start] --> B{Decision}
    B -->|Yes| C[OK]
    B -->|No| D[Cancel]

""")


**Supported Diagrams**: flowchart, sequence, class, state, gantt, journey, timeline, mindmap

**Requirements**:
- iOS 26+, macOS 26+: Native WebKit rendering
- Earlier versions: Fallback display (shown as code block)

## DesignSystem Theme

```swift
MarkdownView("# Themed Markdown")
    .environment(\.colorPalette, .dark)
    .environment(\.typographyScale, .large)

Module Structure

Module Role
SwiftMarkdownView SwiftUI view entry point; includes MarkdownModel and MarkdownAttributedKit (re-exported)
SwiftMarkdownViewHighlightJS Optional HighlightJS syntax highlighting
SwiftMarkdownViewLaTeX Optional LaTeX math rendering
SwiftMarkdownEditor Markdown editor with live preview

Dependencies

Package Purpose Required
swift-markdown Markdown parsing Yes
swift-design-system Design tokens Yes
HighlightSwift Syntax highlighting Optional

Documentation

License

MIT License - See LICENSE for details.

同じカテゴリの OSS — UI / SwiftUI

swift-design-system

Swift Package

SwiftUI 向けの型安全で拡張可能なデザインシステム

Swift
· UI / SwiftUI
swiftuidesign-systemios

swift-ui-routing

Swift Package

SwiftUI 向けの型安全で宣言的なルーティングライブラリ

Swift
· UI / SwiftUI
swiftuiroutingnavigation

swift-statable

Swift Package

AsyncValue パターンで Observable な状態管理を実現する Swift マクロ

Swift
· UI / SwiftUI
swift-macrostate-managementasync

swift-latex-view

Swift Package

SwiftUI ネイティブな LaTeX 数式レンダリング。LLM 出力にも堅牢

Swift
· UI / SwiftUI
swiftuilatexmath

メモリ & ディスクの二層キャッシュで高速表示する SwiftUI リモート画像

Swift
· UI / SwiftUI
swiftuiimage-cacheasync

Google Slides API の JSON を SwiftUI で描画。A2A アーティファクトのストリーミングに対応

Swift
· UI / SwiftUI
swiftuigoogle-slidesa2a

swift-document-scanner

Swift Package

矩形検出・OCR・カメラ撮影を備えた iOS 向けドキュメントスキャン基盤

Swift
· UI / SwiftUI
iosscannerocr

swift-voice-input

Swift Package

ストリーミング認識とフローティングプレビュー UI を備えたプロトコル指向の音声入力

Swift
· UI / SwiftUI
voicespeechswiftui

© 2026 Kyoichi Taniguchi. All rights reserved.