MarkdownTextView is the primary view component for rendering markdown content with support for syntax highlighting, math equations, tables, and interactive links.
Class Definition
Initialization
Optional provider for recycling views like code blocks and tables. Creates a new provider if not specified.
Properties
Interactive Handlers
Callback invoked when a link is tapped. Receives the link payload (URL or string), text range, and tap location.
Callback invoked when an image is tapped. Receives the image source URL and tap location.
Callback invoked for code block previews. Receives the optional language identifier and attributed code content.
Appearance
The theme used to style markdown elements including fonts, colors, and spacing. Setting this property triggers a re-render.
Content
The currently rendered preprocessed markdown content. This property is read-only.
The underlying text view that displays the rendered content. This property is read-only.
Performance
Throttle interval for content updates in seconds. Defaults to 20 FPS (0.05 seconds). Set to
nil to disable throttling.The scroll view tracked for selection updates. Set via
bindContentOffset(from:). Read-only.Methods
setMarkdown
Set Preprocessed Content
Sets preprocessed markdown content for rendering. This method uses the internal Combine pipeline with throttling.The preprocessed markdown content to render.
Set Raw Markdown String
Sets raw markdown string. Parsing, syntax highlighting, and math rendering are performed on a background queue. Cancels any in-flight preprocessing when new content arrives.The raw markdown string to parse and render.
setMarkdownManually
Sets preprocessed content directly, bypassing the Combine pipeline. Use this for synchronous updates without throttling.The preprocessed markdown content to render immediately.
reset
Resets the view to an empty state, clearing all content and cached rendering data.bindContentOffset
Binds text selection updates to a scroll view’s content offset changes.The scroll view to track for selection updates, or
nil to unbind.boundingSize
Calculates the bounding size for the markdown content at a given width.The maximum width constraint.
The calculated size that fits the content.
Platform Support
MarkdownTextView is available on:- iOS (inherits from
UIView) - macOS (inherits from
NSView) - visionOS (via
UIView)