Highlightr是用Swift建造的iOS&MacOS語法熒光筆。它使用亮點。 JS作為核心,支持185種語言,並配備89種樣式。
用代碼將la腳的字符串帶到帶有適當的語法突出顯示的NSATTRIBUTTERTRING。
Cocoapods是可可項目的依賴性經理。您可以使用以下命令安裝它:
$ gem install cocoapods要使用Cocoapods將Highlightr集成到您的Xcode項目中,請在您的Podfile中指定:
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
target '<Your Target Name>' do
pod 'Highlightr'
end然後,運行以下命令:
$ pod install迦太基是一個分散的依賴管理器,可建立您的依賴關係並為您提供二進制框架。
您可以使用以下命令使用Homebrew安裝迦太基:
$ brew update
$ brew install carthage要使用迦太基將Highlightr集成到您的Xcode項目中,請在您的Cartfile中指定:
github "raspu/Highlightr"
運行carthage update以構建框架並將構建的Highlightr.framework拖到您的Xcode Project.highlightr
Highlightr提供了兩個主要類:
這是主要端點,您可以使用它將代碼字符串轉換為NSATTRIB的字符串。
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 " )
NstextStorage的子類,您可以使用它實時突出顯示文本。
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 ) 是的,Highlightr依靠iOS和MacOS JavaScriptCore使用亮點。 JS解析代碼。這實際上很快!
它永遠不會像本地解決方案那樣快,但是足夠快,可以在實時編輯器上使用。
它帶有一個定制的HTML解析器,用於創建NSATTRIBUTTEDSTRINGS,正在預處理主題,並正在預加載JS庫。結果,在我的iPhone 6s上花費大約50毫秒來處理500行代碼。
您可以找到有關可可二麥最新版本的文檔。
Highlightr可根據MIT許可獲得。有關更多信息,請參見許可證文件。
亮點可在BSD許可下獲得。您可以在此處找到許可證文件。