STTextView-Plugin-Neon icon indicating copy to clipboard operation
STTextView-Plugin-Neon copied to clipboard

Source Code Syntax Highlighting

STTextView Source Code Syntax Highlighting with TreeSitter and Neon.

Installation

Add the plugin package as a dependency of your application, then register/add it to the STTextView instance:

import NeonPlugin

textView.addPlugin(
    NeonPlugin(
        theme: .default,
        language: .go
    )
)

SwiftUI:

import SwiftUI
import STTextViewUI
import NeonPlugin

struct ContentView: View {
    @State private var text: AttributedString = ""
    @State private var selection: NSRange?
    var body: some View {
        STTextViewUI.TextView(
            text: $text,
            selection: $selection,
            options: [.wrapLines, .highlightSelectedLine],
            plugins: [NeonPlugin(theme: .default, language: .go)]
        )
        .textViewFont(.monospacedDigitSystemFont(ofSize: NSFont.systemFontSize, weight: .regular))
        .onAppear {
            loadContent()
        }
    }

    private func loadContent() {
        // (....)
        self.text = AttributedString(string)
    }
}
Default Theme