Skip to content
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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Sources/SpeziViews/Views/Text/MarkdownView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Copy link
Member

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:

Suggested change

/// - Parameters:
/// - asyncMarkdown: An async closure to load the markdown in an utf8 representation.
/// - state: A `Binding` to observe the ``ViewState`` of the ``MarkdownView``.
Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The 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 //Example should be removed and I would suggest to rather add an explanation around the example block.

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)
Copy link
Member

Choose a reason for hiding this comment

The 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 .full?

) else {
state = .error(Error.markdownLoadingError)
return AttributedString(
Expand Down
15 changes: 14 additions & 1 deletion Sources/SpeziViews/Views/Text/TextContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The 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):
Expand Down
Loading