Skip to content

JeremyAgost/okudakit

 
 

Repository files navigation

OkudaKit

What is it?

An open source (BSD-license) Cocoa Framework for adding syntax highlighting to Cocoa applications using CSS. It was started by Todd Ditchendorf. This fork delivering iOS support is courtesy of Jeremy Agostino.

Why is it cool?

OkudaKit produces syntax highlighted NSAttributedStrings for use in NSTextViews (or similar display outlets) via CSS stylesheets.

How?

Provide a simple BNF-style grammar for a language (like, say, JSON) and a CSS stylesheet which lists style rules for the productions found in the language grammar. Name your grammar and CSS files something like json.grammar (example) and json.css (example), put them in your app’s bundle, and add a few lines of code like this:

NSString *s = ... // get a JSON string
OKSyntaxHighlighter *highlighter = [OKSyntaxHighlighter syntaxHighlighter];
NSAttributedString *str = [highlighter highlightedStringForString:s ofGrammar:@"json"];
[textView setString:str]; // display

Voilà, syntax-highlighted JSON.

Why does it suck?

OkudaKit is currently at version 0.1 which gives you an idea of how mature I think it is. Current suckiness includes (but is not limited to):

  • No error recovery. Your display string must match the grammar provided.
  • Displayed Syntax Highlighting is read-only. No support for live syntax highlight updating (needed for text editors).
  • Only 3 languages are currently supported: HTML, CSS, and JSON. But adding new languages is easy.

I’m working on these problems now. Stay tuned.

What are the requirements?

  • Mac OS X Leopard or later
  • iOS 3.2/4.0 or later
  • ParseKit (included in the OkudaKit source)

WebKit isn’t required?

No.

iPhone OS?

iOS 3.2/4.0 and higher has support for NSAttributedString but it’s somewhat gutted compared to the Mac OS X version. One of the reasons I forked this was to make OkudaKit actually build on iOS. You’d have to find a third party library to display any attributed text, since things like UILabel don’t have any support for it.

About

Cocoa Syntax Highlighting via CSS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Objective-C 98.6%
  • C 1.4%