Implementing a Markdown editor with Preview
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 to Markdown tags in the Text
components.
In this recipe, we'll experiment with Markdown, implementing a simple text editor.
Getting ready
This recipe doesn't require any particular preliminary operations apart from creating an 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 and a preview where the text is rendered as rich text, with bold, italics, and so on.
EditorView
has a tab bar above the editor itself for adding tags for bold, italics, strikethrough, and code.
Let's get started. Follow these steps...