-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
36cb86d
commit 3552aba
Showing
5 changed files
with
70 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import SwiftUI | ||
|
||
/// A view that renders basic Markdown content using SwiftUI Text. | ||
/// | ||
/// `MarkdownView` provides a lightweight way to display formatted Markdown text | ||
/// using SwiftUI's built-in AttributedString markdown parsing. | ||
/// | ||
/// ## Usage | ||
/// ```swift | ||
/// MarkdownView("# Hello\nThis is **bold** and *italic* text") | ||
/// ``` | ||
struct MarkdownView: View { | ||
/// The formatted content to be displayed | ||
private let content: AttributedString | ||
|
||
/// Creates a new MarkdownView with the specified content. | ||
/// | ||
/// - Parameter content: A string containing Markdown-formatted text | ||
init(_ content: String) { | ||
do { | ||
self.content = try AttributedString(markdown: content) | ||
} catch { | ||
print("Error parsing markdown: \(error)") | ||
self.content = AttributedString(content) | ||
} | ||
} | ||
|
||
var body: some View { | ||
Text(content) | ||
.textSelection(.enabled) | ||
.frame(maxWidth: .infinity, alignment: .leading) | ||
.padding() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters