|Platforms||ios 7.0, osx 10.7, requires ARC|
#import <Prism/Prism.h> // ... PRISyntaxHighlighter *highlighter = [[PRISyntaxhighlighter alloc] initWithDefaultAliases:YES]; NSString *output = [highlighter highlight:@"int" asLanguage:@"objc" error:NULL]; NSLog(@"%@", output); // <span class="token keyword">int</span>
The main class is
PRISyntaxHighlighter. It constructs Prism internally when
init it. After that, you can use
-highlight:asLanguage:error: to highlight code snippets.
The language names you pass into when you perform highlighting need to be one of the followings:
- A built-in definition that is a key of
- One of the language aliases that is a key of
You can add/remove aliases using
-removeAlias:. An alias should point to a built-in language name, or another alias.
A set of recommended aliases is provided via
+defaultAliases. Note that they are not loaded if you use
init to initialise
Prism provides some built-in styling. You can get a set of themes and URLs pointing to their respective CSS files via
There’s a demo project in the
PrismDemo directory showing what this library can do. You can build it on OS X in Xcode by opening
Prism.xcworkspace and run the PrismDemo scheme.
This repository can build as an OS X framework that you can use directly. Alternatively you can also install via CocoaPods:
pod install Prism
Since the original Prism needs to be bundled with the main application, I don’t recommend you just try to include this as a submodule or even copy-paste the code. You will need to structure your project very carefully so that resources can be found correctly. It can work, but you’ll waste a lot of time to this.
- Support built-in Prism plugins.
- Support external Prism plugins.
- Travis CI.
- Test Coverage.
- Proper documentation.
Fri, 04 Mar 2016 09:56:03 +0000