Forked Highlightr.
A SwiftUI view that automatically highlights code syntax using Highlightr, which is using highlight.js as it core, and supports 185 languages and comes with 89 styles.
Highlightr renders your syntax colored code as a string, no web views involved. This means your SwiftUI layout behaves like you'd expect it to, automatically reporting its frame, and no embedded scroll views.
Since we're using AttributedString
, this package requires macOS 12 or iOS 15.
This package adds
- SwiftUI view for syntax coloring
- Safe selection of themes via enum
- Dark mode detection
Add this repo's URL to your project's package dependencies: https://github.com/mortenjust/CodeHighlighter
CodeTextView("let a = b(\"Here we are\");")
CodeTextView("console.log(\"hello highlight\");",
language: "javascript",
lightTheme: .solarizedLight,
darkTheme: .solarizedDark)
- A
CodeTextEditor
, a text editor that lets you edit text with realtime highlighting. Highlightr offers CodeAttributedString, which is a subclass ofNSTextStorage
, so this could be implemented with a hostedUI/NSTextView
.
MIT