Syntax coloring for Cocoa app

后端 未结 5 2054
感情败类
感情败类 2020-12-28 11:24

I\'m planning to do a Cocoa app that requires code syntax to be colored (in all common languages). Instead of writing my own code highlighter/parser, are there any pre-made

相关标签:
5条回答
  • 2020-12-28 11:44

    You can also use the JavaScript library SyntaxHighlighter and embed it into a WebView into your app.

    0 讨论(0)
  • 2020-12-28 11:44

    You can use highlight that is used in QLColorCode :) (however, it's not a Framework that you include in your code, but a command-line utility)

    EDIT: Ah yeah, use Geshi, it's probably better :D

    0 讨论(0)
  • 2020-12-28 11:46

    After quite a bit of research trying to solve a similar problem, the simplest approach I found by far is to use a JavaScript library for syntax highlighting combined with a WebView. Spending time writing a syntax highlighter, a fairly complex task, is probably not what you'd want to spend time on.

    I settled on using the popular CodeMirror and wrote an open source wrapper for Cocoa: https://github.com/swisspol/CodeMirrorView. You can use similar approaches to wrap other JavaScript based code editors in Cocoa apps.

    0 讨论(0)
  • 2020-12-28 11:47

    You might be able to use something like Geshi, but there're also the resources listed here: http://www.cocoadev.com/index.pl?SyntaxHighlighting

    Edit

    More links:

    • Syntax Highlighting in Cocoa TextView? Experiences? Suggestions? Ideas?
    • http://parsekit.com/okudakit/
    0 讨论(0)
  • 2020-12-28 11:54

    An excellent solution is Uli Kusterer's UKSyntaxColoredTextDocument. It is fast and has several built-in syntax parsers. It's easy to add new languages.

    It's free for non-commercial use and very cheap if you want it for a commercial app.

    0 讨论(0)
提交回复
热议问题