You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Takes your lame string with code and returns a NSAttributtedString with proper syntax highlighting.
Installation
Requirements
iOS 8.0+
macOS 10.10+
SPM
Click the File menu, select Add Packages…
Enter https://github.com/raspu/Highlightr/ into the Search or Enter Package URL search field
Link Highlightr to your application target
Finally, add import MarkdownUI to your source code.
CocoaPods & Carthage
CocoaPods & Carthage are no longer supported.
Usage
Highlightr provides two main classes:
Highlightr
This is the main endpoint, you can use it to convert code strings into NSAttributed strings.
lethighlightr=Highlightr()
highlightr.setTheme(to:"paraiso-dark")letcode="let a = 1"
// You can omit the second parameter to use automatic language detection.
lethighlightedCode= highlightr.highlight(code, as:"swift")
CodeAttributedString
A subclass of NSTextStorage, you can use it to highlight text on real time.
Yes, Highlightr relies on iOS & macOS JavaScriptCore to parse the code using highlight.js. This is actually quite fast!
Performance
It will never be as fast as a native solution, but it's fast enough to be used on a real time editor.
It comes with a custom made HTML parser for creating NSAttributtedStrings, is pre-processing the themes and is preloading the JS libraries. As result it's taking around of 50 ms on my iPhone 6s for processing 500 lines of code.
Documentation
You can find the documentation for the latest release on cocoadocs.
License
Highlightr is available under the MIT license. See the LICENSE file for more info.
Highlight.js is available under the BSD license. You can find the license file here.