1

I'm writing a small markdown editor for OS X. So far I can convert the markdown to HTML and get it appearing in my web view. What I haven't managed yet is to get syntax-highlighting up and running. I'm using kramdown to do the markdown -> HTML bit, and its docs suggest that the highlighting can be accomplished with rouge or coderay. I've gone with rouge, but haven't had much success. Here's how I set up the task:

func newTask() -> NSTask {

    var task = NSTask()
    task.launchPath = "/usr/bin/kramdown"
    task.arguments = [
        "--syntax-highlighter", "rouge",
        "--syntax-highlighter-opts", "{line_numbers : true, disable : false, default_lang : python}"]

    var inPipe  = NSPipe()
    var outPipe = NSPipe()

    task.standardInput  = inPipe
    task.standardOutput = outPipe

    return task

}

And here's an example of my markdown:

~~~ ruby
def what?
  42
end
~~~

When I run the task I don't get any error messages, and I can toggle line numbers using the arguments I pass to --syntax-highlighter-opts, so I think the syntax of the arguments is correct, but something else clearly isn't - I can extract the html, but there's no syntax highlighting.

Paul Patterson
  • 6,840
  • 3
  • 42
  • 56
  • If the line numbers are working, then I suspect it is working fine. Have you looked at the generated HTML? Is the code wrapped in various HTML elements to identify the various parts? If so, then you need to provide some CSS to tell the browser how to style the code. – Waylan Dec 07 '15 at 19:37
  • If that is, in fact, your problem, https://github.com/jneen/rouge/issues/343 provides some info on how to get the default themes as CSS files. – Waylan Dec 07 '15 at 19:55

0 Answers0