Implementing a Markdown editor with preview functionality
Markdown is a lightweight markup language to create rich text using a text editor. In recent years, it has become ubiquitous: you can use it in GitHub, when asking and replying to questions in Stack Overflow, for messaging in Discord, and more.
SwiftUI provides support for Markdown tags in the Text
views.
In this recipe, we’ll experiment with Markdown, implementing a simple text editor.
Getting ready
This recipe doesn’t require any preliminary operations. Create a new Xcode project called MarkdownEditor
.
How to do it…
Taking inspiration from the GitHub pull request comment textbox, we are going to implement an app with two tabs: a text editor view and a preview view, where the text is rendered as rich text, with bold, italics, and so on.
The text editor view will have a tab bar above the editor itself for adding Markdown tags for the bold, italics, strikethrough, and code formats...