https://github.com/krzyzanowskim/sttextview-plugin-neon
Source Code Syntax Highlighting
https://github.com/krzyzanowskim/sttextview-plugin-neon
plugin sttextview textview
Last synced: about 1 year ago
JSON representation
Source Code Syntax Highlighting
- Host: GitHub
- URL: https://github.com/krzyzanowskim/sttextview-plugin-neon
- Owner: krzyzanowskim
- License: mit
- Created: 2023-08-19T14:07:04.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-02-12T00:13:58.000Z (over 2 years ago)
- Last Synced: 2024-04-14T04:55:38.065Z (about 2 years ago)
- Topics: plugin, sttextview, textview
- Language: Swift
- Homepage:
- Size: 35.2 KB
- Stars: 18
- Watchers: 2
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[STTextView](https://github.com/krzyzanowskim/STTextView) Source Code Syntax Highlighting with [TreeSitter](https://tree-sitter.github.io/tree-sitter/) and [Neon](https://github.com/ChimeHQ/Neon).
https://github.com/user-attachments/assets/910b9862-c682-4dcc-ae0e-dbb55e8a3fe5
## Installation
Add the plugin package as a dependency of your application, then register/add it to the STTextView instance:
```swift
import NeonPlugin
textView.addPlugin(
NeonPlugin(
theme: .default,
language: .swift
)
)
```
SwiftUI:
```swift
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: .swift)]
)
.textViewFont(.monospacedDigitSystemFont(ofSize: NSFont.systemFontSize, weight: .regular))
.onAppear {
loadContent()
}
}
private func loadContent() {
// (....)
self.text = AttributedString(string)
}
}
```