https://github.com/meniny/highlightjs.swift
✨A code syntax highlight library using Highlight.js
https://github.com/meniny/highlightjs.swift
Last synced: about 1 year ago
JSON representation
✨A code syntax highlight library using Highlight.js
- Host: GitHub
- URL: https://github.com/meniny/highlightjs.swift
- Owner: Meniny
- License: mit
- Created: 2017-07-21T06:47:38.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-07-21T11:05:06.000Z (almost 9 years ago)
- Last Synced: 2025-04-07T12:16:18.217Z (about 1 year ago)
- Language: Swift
- Homepage:
- Size: 575 KB
- Stars: 19
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HighlightJS.swift
## What's this?
`HighlightJS.swift` is a code syntax highlight library using [Highlight.js](https://highlightjs.org).
Supports 169 languages and 80 themes.


## Requirements
* iOS 8.0+
* macOS 10.11+
* tvOS 9.0+
* Xcode 8 with Swift 3
## Installation
#### CocoaPods
```ruby
pod 'HighlightJS'
```
## Contribution
You are welcome to fork and submit pull requests.
## License
`HighlightJS.swift` is open-sourced software, licensed under the `MIT` license.
## Usage
#### HighlightJS
```swift
let textStorage = HighlightJSAttributedString()
let layoutManager = NSLayoutManager()
textStorage.addLayoutManager(layoutManager)
let textContainer = NSTextContainer(size: CGSize.zero)
layoutManager.addTextContainer(textContainer)
let textView = UITextView(frame: rect, textContainer: textContainer)
view.addSubview(textView)
var highlighter = textStorage.highlightJS
textStorage.language = HighlightJS.LanguageName.rawValue // "swift"
textStorage.highlightJS.setTheme(to: HighlightJS.ThemeName.rawValue) // "solarized-light"
textView.text = "func test() {}"
```
#### HighlightView (1.1.0+, iOS only)
```swift
let h = HighlightView(frame: rect)
view.addSubview(h)
h.language = .swift
h.theme = .solarizedLight
h.text = "func test() {}"
```
***
> Checkout the sample project for more detail.