A SwiftUI view for macOS that renders markdown text with selectable text blocks. Built for displaying markdown content with interactive features, such as highlighting selected text and positioning an actionable button at the selection's bounding rectangle.
InteractiveTextView
was originally developed for a macOS LLM chat interface, where markdown rendering and text selection were critical for displaying conversations and enabling user interactions. Now, it’s available as a Swift package for any macOS app that needs to render markdown—whether in a single view or as part of a chat-like conversation list.
- Markdown Rendering: Supports basic markdown syntax, including headers, lists, inline code, bold text, and code blocks with syntax highlighting.
- Text Selection: Allows users to select text blocks, with the selected text and its bounding rectangle position exposed for custom actions.
- Dynamic Layout: Automatically adjusts height based on content, perfect for use in scrollable views like chat interfaces.
- Theming Support: Adapts to light and dark modes using SwiftUI’s
colorScheme
environment. - Customizable: Easily integrate into your SwiftUI app with configurable width and bindings for height, selected text, and button position.
Add InteractiveTextView
to your project using Swift Package Manager.
- In Xcode, go to
File > Add Packages...
. - Enter the repository URL: https://github.com/omartorresrios/InteractiveTextView.git
- Specify the version or branch you want to use, then click
Add Package
.
Here’s how to use InteractiveTextView
in your SwiftUI app:
For a chat-like interface with multiple messages, you can use InteractiveTextView
inside a ScrollView
:
You can look at the demos inside the Example folder and start tinkering! Here are some screenshots:
singleview.mov
multipleviews.mov
Only text

Only code

Text and code

One of the coolest features is that you can highlight text, retrieve its value, and perform actions with by clicking a button.
- macOS 12.0 or later
- Swift 5.5 or later
- Xcode 13 or later
There are a lot of cool stuff I want to add, such as:
- Customize the actionable button (font, text color, backgrond color).
- Custom fonts, text and background colors.
- Create some default palette colors.
- Expand/collapse
InteractiveTextView
- And more!
Also, if you have more ideas, please hit me up, and we’ll chat about how we can make it even more powerful!
Contributions are welcome! If you’d like to improve InteractiveTextView
, please:
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature
). - Commit your changes (
git commit -m 'Add your feature'
). - Push to the branch (
git push origin feature/your-feature
). - Open a pull request.
InteractiveTextView
is available under the MIT License. See the LICENSE file for more details.