-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented small change to markdown formatting, and added docs #34
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,7 @@ public struct MarkdownView: View { | |
|
||
|
||
/// Creates a ``MarkdownView`` that displays the content of a markdown file as an utf8 representation that is loaded asynchronously. | ||
|
||
/// - Parameters: | ||
/// - asyncMarkdown: An async closure to load the markdown in an utf8 representation. | ||
/// - state: A `Binding` to observe the ``ViewState`` of the ``MarkdownView``. | ||
|
@@ -95,14 +96,18 @@ public struct MarkdownView: View { | |
/// Parses the incoming markdown and handles the view's error state management. | ||
/// - Parameters: | ||
/// - markdown: A `Data` instance containing the markdown file in an utf8 representation. | ||
/// | ||
/// ```swift | ||
/// // Example | ||
/// Data(" # This is a markdown example | ||
/// *This should be italiced* and **this bolded**").utf8 | ||
/// ``` | ||
Comment on lines
+99
to
+103
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code example does not compile, if you want to create a String with line breaks you will have to use a multi-line string interval: https://docs.swift.org/swift-book/documentation/the-swift-programming-language/stringsandcharacters/#Multiline-String-Literals In addition, the code example does not call the API. Comments like Last but not least, I would move the example above the parameters section of the code documentation. |
||
/// - Returns: Parsed Markdown as an `AttributedString` | ||
@MainActor private func parse(markdown: Data) -> AttributedString { | ||
state = .processing | ||
|
||
guard let markdownString = try? AttributedString( | ||
markdown: markdown, | ||
options: .init(interpretedSyntax: .inlineOnlyPreservingWhitespace) | ||
options: .init(interpretedSyntax: .inlineOnly) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the reason for this change? Wouldn't it make sense to switch to |
||
) else { | ||
state = .error(Error.markdownLoadingError) | ||
return AttributedString( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,11 +8,24 @@ | |
|
||
import Foundation | ||
|
||
|
||
/// The `TextContent` enum represents either a plain string or a localized string resource. | ||
/// | ||
/// Use this enum to encapsulate text content in your application, allowing flexibility in handling localized and non-localized strings. | ||
/// | ||
/// ```swift | ||
/// // Example usage: | ||
/// let content: TextContent = .localized(LocalizedStringResource("HELLO_SPEZI", bundle: .main)) | ||
/// let localizedString = content.localizedString(for: .current) | ||
/// print(localizedString) // Prints the localized string for the current locale. | ||
/// ``` | ||
Comment on lines
+15
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the added documentation! The same comments about the example also apply here as well. |
||
enum TextContent { | ||
case string(_ value: String) | ||
case localized(_ value: LocalizedStringResource) | ||
|
||
/// Returns the localized string representation of the content for a given locale. | ||
/// | ||
/// - Parameter locale: The locale for which to retrieve the localized string. | ||
/// - Returns: The localized string corresponding to the content. | ||
func localizedString(for locale: Locale) -> String { | ||
switch self { | ||
case let .string(string): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the empty line added here, it breaks the documentation block: