HighlightSwiftSyntax

Outputs highlighted Swift Code as NSAttributedString using apple/swift-syntax

let inputCode = """
let inputCode: String
let rangeToKind: [NSRange: MyWordKind]

override public func visit(_ node: TupleExprElementSyntax) -> Syntax {
    if let label = node.label {
        updateDict(location: label.positionAfterSkippingLeadingTrivia.utf8Offset,
                   length: label.contentLength.utf8Length,
                   kind: .argument)
    }
    return super.visit(node)
}
"""

let output = try SwiftHighlighter.highlight(inputCode)

Screenshot 2022-10-22 at 18 02 05

Theme

Currently it uses the theme from https://github.com/atacan/Amaze-Midnight. Custom theme functionality is coming soon…

GitHub

View Github