Latest 1.1.0
Homepage https://github.com/Meniny/HighlightJS.swift
License MIT
Platforms ios 8.0, osx 10.11, tvos 9.0
Frameworks Foundation, JavaScriptCore
Authors

HighlightJS.swift

What’s this?

HighlightJS.swift is a code syntax highlight library using Highlight.js.

Supports 169 languages and 80 themes.

preview

preview

Requirements

  • iOS 8.0+
  • macOS 10.11+
  • tvOS 9.0+
  • Xcode 8 with Swift 3

Installation

CocoaPods

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

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)

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.

Latest podspec

{
    "name": "HighlightJS",
    "version": "1.1.0",
    "summary": "A code syntax highlight library using Highlight.js",
    "homepage": "https://github.com/Meniny/HighlightJS.swift",
    "license": "MIT",
    "authors": {
        "Meniny": "[email protected]"
    },
    "source": {
        "git": "https://github.com/Meniny/HighlightJS.swift.git",
        "tag": "1.1.0"
    },
    "social_media_url": "https://meniny.cn/",
    "platforms": {
        "ios": "8.0",
        "osx": "10.11",
        "tvos": "9.0"
    },
    "ios": {
        "source_files": [
            "HighlightJS/Classes/**/*.swift",
            "HighlightJS/iOS/**/*.swift"
        ]
    },
    "osx": {
        "source_files": "HighlightJS/Classes/**/*.swift"
    },
    "tvos": {
        "source_files": "HighlightJS/Classes/**/*.swift"
    },
    "resources": "HighlightJS/Assets/**/*.*",
    "frameworks": [
        "Foundation",
        "JavaScriptCore"
    ],
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This