A powerful pure UIKit framework for rendering Markdown documents with real-time parsing and rendering capabilities. Battle tested in FlowDown.
This is a fork of Lakr233/MarkdownView with enhancements for Open UI, an iOS client for Open WebUI.
- Links are now tappable out of the box — a default
linkHandleropens URLs in Safari viaUIApplication.shared.open(url) - No additional configuration needed; works automatically in SwiftUI via
MarkdownView("text")
- Swapped Highlightr (Obj-C JSContext) → HighlightSwift (pure Swift JavaScriptCore)
- Lazy async per-block highlighting: Code blocks render plain monospaced text immediately, then highlight asynchronously with a 300ms debounce — no color flickering during streaming
- Dark mode:
.dark(.github)theme with automatic light/dark switching - LRU cache: Highlighted results are cached to avoid re-highlighting on scroll
- Paragraph spacing, line spacing, heading spacing, blockquote spacing, and blockquote indent are now configurable via
theme.spacings(previously hardcoded to 16/4) - List spacing follows theme settings
- Plain numbered lists: Replaced circled emoji numbers (①②③) with plain
1.2.3.CoreText rendering viaCTLineDraw - Dynamic indent: Measures max number width in a list and uses that + padding as the base indent — scales correctly for any list size
- Left-aligned numbers: Fixed position like bullet points for consistent alignment
- Changed emphasis rendering from underline to italic font (matches standard markdown conventions)
- Code blocks use actual
intrinsicContentSizeinstead of a formula-based height calculation — fixes extra bottom whitespace
- 🚀 Real-time Rendering: Live Markdown parsing and rendering as you type
- 🖥️ Specialized for Mobile Display: Optimized layout that extracts complex elements from lists for better readability
- 🎨 Syntax Highlighting: Beautiful code syntax highlighting with HighlightSwift
- 📊 Math Rendering: LaTeX math formula rendering with SwiftMath
- 📱 Cross-Platform: Native support for iOS, macOS, Mac Catalyst, and visionOS
- 🔗 Clickable Links: Links open in Safari automatically — no setup required
Add the following to your Package.swift file:
dependencies: [
.package(url: "https://github.com/Ichigo3766/MarkdownView", branch: "main"),
]Platform compatibility:
- iOS 16.0+
- macOS 13.0+
- Mac Catalyst 16.0+
- visionOS 1.0+
import MarkdownView
struct ContentView: View {
var body: some View {
MarkdownView("# Hello World\n\nLinks are [clickable](https://example.com) by default!")
}
}With custom theme:
MarkdownView("# Hello World", theme: .default)import MarkdownView
import MarkdownParser
let markdownTextView = MarkdownTextView()
let parser = MarkdownParser()
let result = parser.parse("# Hello World")
let content = MarkdownTextView.PreprocessedContent(parserResult: result, theme: .default)
markdownTextView.setMarkdown(content)
// Links are clickable by default, or set a custom handler:
markdownTextView.linkHandler = { payload, range, point in
switch payload {
case .url(let url): UIApplication.shared.open(url)
case .string(let str): if let url = URL(string: str) { UIApplication.shared.open(url) }
}
}Check out the included example project to see MarkdownView in action:
cd Example
open Example.xcodeprojThis project is licensed under the MIT License. See the LICENSE file for details.
- Original framework by Lakr233
- Code adapted from swift-markdown-ui by Guillermo Gonzalez, used under the MIT License.
Copyright 2025 © Lakr Aream. All rights reserved.
%20-%202025-05-27%20at%2003.03.27.png)