diff --git a/Sources/HighlightSwift/Highlight/Highlight.swift b/Sources/HighlightSwift/Highlight/Highlight.swift index 3dacdd7..e76208c 100644 --- a/Sources/HighlightSwift/Highlight/Highlight.swift +++ b/Sources/HighlightSwift/Highlight/Highlight.swift @@ -5,6 +5,13 @@ public actor Highlight { private var hljs: JSValue? private static let shared = Highlight() + /// Attempts to syntax highlight the specified text. + /// - Parameters: + /// - text: The plain text code to highlight. + /// - language: The language to use (default: nil/automatic). + /// - style: The highlight color style to use (default: .stackoverflow/.light). + /// - Throws: Either a HighlightError or an Error. + /// - Returns: The result of the syntax highlight. public static func text(_ text: String, language: String? = nil, style: HighlightStyle = HighlightStyle(.stackoverflow)) async throws -> HighlightResult { diff --git a/Sources/HighlightSwift/Views/CodeCard.swift b/Sources/HighlightSwift/Views/CodeCard.swift index 42eabba..b83d880 100644 --- a/Sources/HighlightSwift/Views/CodeCard.swift +++ b/Sources/HighlightSwift/Views/CodeCard.swift @@ -22,8 +22,13 @@ public struct CodeCard: View { let initialTextStyle: Font.TextStyle let initialStyleName: HighlightStyle.Name + /// Creates a card view that displays syntax highlighted code. + /// - Parameters: + /// - text: The code as plain text + /// - textStyle: The initial font text style (default: .caption). + /// - style: The initial highlight color style (default: .stackoverflow). public init(_ text: String, - textStyle: Font.TextStyle = .caption2, + textStyle: Font.TextStyle = .caption, style: HighlightStyle.Name = .stackoverflow) { self.text = text self.initialStyleName = style @@ -175,7 +180,7 @@ struct CodeCard_Previews: PreviewProvider { static var previews: some View { ScrollView { - CodeCard(python, textStyle: .caption) + CodeCard(python, textStyle: .callout, style: .solarFlare) .padding() } } diff --git a/Sources/HighlightSwift/Views/CodeText.swift b/Sources/HighlightSwift/Views/CodeText.swift index 258e28f..31a8d14 100644 --- a/Sources/HighlightSwift/Views/CodeText.swift +++ b/Sources/HighlightSwift/Views/CodeText.swift @@ -20,6 +20,13 @@ public struct CodeText: View { let showBackground: Bool let onHighlightResult: ((HighlightResult) -> Void)? + /// Creates a text view that displays syntax highlighted code. + /// - Parameters: + /// - text: The plain text code to highlight. + /// - style: The highlight color style to use (default: .stackoverflow). + /// - language: The language to use (default: nil/automatic). + /// - showBackground: Show the background of the highlight color style (default: false). + /// - onHighlightResult: Callback with the result of the syntax highlight (default: nil). public init(_ text: String, style: HighlightStyle.Name = .stackoverflow, language: String? = nil,