All Projects → raspu → Highlightr

raspu / Highlightr

Licence: mit
iOS & OSX Syntax Highlighter.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Highlightr

Refractor
Lightweight, robust, elegant virtual syntax highlighting using Prism
Stars: ✭ 291 (-73.92%)
Mutual labels:  syntax-highlighting, highlight
Alfred Hl
🔆 Syntax highlight code in the clipboard
Stars: ✭ 80 (-92.83%)
Mutual labels:  syntax-highlighting, highlight
Yii2 Quill
Yii 2 implementation of Quill, modern WYSIWYG editor
Stars: ✭ 52 (-95.34%)
Mutual labels:  syntax-highlighting, highlight
geshi-1.1
Next generation of Generic Syntax Highlighter for PHP
Stars: ✭ 70 (-93.73%)
Mutual labels:  syntax-highlighting, highlight
enhanced-slack
🌴 PoC Slack enhancer/injector
Stars: ✭ 48 (-95.7%)
Mutual labels:  syntax-highlighting, highlight
go-highlight
A Go (Golang) code syntax highlighting library.
Stars: ✭ 20 (-98.21%)
Mutual labels:  syntax-highlighting, highlight
Geshi 1.0
Original version of Generic Syntax Highlighter for PHP
Stars: ✭ 149 (-86.65%)
Mutual labels:  syntax-highlighting, highlight
see-cli
A colorful 🌈 cat - syntax highlight print CLI
Stars: ✭ 24 (-97.85%)
Mutual labels:  syntax-highlighting, highlight
Lowlight
Virtual syntax highlighting for virtual DOMs and non-HTML things
Stars: ✭ 310 (-72.22%)
Mutual labels:  syntax-highlighting, highlight
Influx Prompt
An interactive command-line InfluxDB cli with auto completion.
Stars: ✭ 42 (-96.24%)
Mutual labels:  syntax-highlighting
Dhall Vim
Syntax highlighting for Dhall
Stars: ✭ 51 (-95.43%)
Mutual labels:  syntax-highlighting
Language Vue Component
Adds syntax highlighting to Vue Component files in Atom
Stars: ✭ 39 (-96.51%)
Mutual labels:  syntax-highlighting
Ft Syntax Highlight
Pure CSS syntax highlighter, no Javascript required. Includes built-in tooltips with UI themes and syntax highlighting themes
Stars: ✭ 42 (-96.24%)
Mutual labels:  syntax-highlighting
Remark Boilerplate
A boilerplate to create presentations using remark, Gulp, Stylus and more.
Stars: ✭ 41 (-96.33%)
Mutual labels:  highlight
Vim Systemd Syntax
Syntax highlighting for systemd service files in Vim.
Stars: ✭ 57 (-94.89%)
Mutual labels:  syntax-highlighting
Downlit
Syntax Highlighting and Automatic Linking
Stars: ✭ 39 (-96.51%)
Mutual labels:  syntax-highlighting
Highr
Syntax Highlighting for R Source Code
Stars: ✭ 36 (-96.77%)
Mutual labels:  syntax-highlighting
Syntax Highlighter Bot
Syntax highlighter bot for telegram.
Stars: ✭ 60 (-94.62%)
Mutual labels:  syntax-highlighting
Brew.vim
🍺 Vim Syntax for Homebrew formulae
Stars: ✭ 55 (-95.07%)
Mutual labels:  syntax-highlighting
Vim Html Template Literals
Syntax highlighting for html template literals in javascript (as in lit-html and polymer 3)
Stars: ✭ 48 (-95.7%)
Mutual labels:  syntax-highlighting

Highlightr

Version Carthage Compatible CocoaPods License Platform

Highlightr is an iOS & macOS syntax highlighter built with Swift. It uses highlight.js as it core, supports 185 languages and comes with 89 styles.

Takes your lame string with code and returns a NSAttributtedString with proper syntax highlighting.

Sample Gif A Sample Gif B

Installation

Requirements

  • iOS 8.0+
  • macOS 10.10+

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate Highlightr into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!

target '<Your Target Name>' do
    pod 'Highlightr'
end

Then, run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate Highlightr into your Xcode project using Carthage, specify it in your Cartfile:

github "raspu/Highlightr"

Run carthage update to build the framework and drag the built Highlightr.framework into your Xcode project.Highlightr

Usage

Highlightr provides two main classes:

Highlightr

This is the main endpoint, you can use it to convert code strings into NSAttributed strings.

	let highlightr = Highlightr()
	highlightr.setTheme(to: "paraiso-dark")
	let code = "let a = 1"
	// You can omit the second parameter to use automatic language detection.
	let highlightedCode = highlightr.highlight(code, as: "swift") 
	

CodeAttributedString

A subclass of NSTextStorage, you can use it to highlight text on real time.

	let textStorage = CodeAttributedString()
	textStorage.language = "Swift"
	let layoutManager = NSLayoutManager()
	textStorage.addLayoutManager(layoutManager)

	let textContainer = NSTextContainer(size: view.bounds.size)
	layoutManager.addTextContainer(textContainer)

	let textView = UITextView(frame: yourFrame, textContainer: textContainer)

JavaScript?

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].