Skip to content

Commit

Permalink
Add code documentation comments
Browse files Browse the repository at this point in the history
  • Loading branch information
appstefan committed May 12, 2023
1 parent b8d20e4 commit f28b0b6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Sources/HighlightSwift/Highlight/Highlight.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 7 additions & 2 deletions Sources/HighlightSwift/Views/CodeCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
}
Expand Down
7 changes: 7 additions & 0 deletions Sources/HighlightSwift/Views/CodeText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit f28b0b6

Please sign in to comment.