Monday, May 3, 2010

Syntax highlighting for golang

I've been using Alex Gorbatchev's SyntaxHighlighter to ease the task of presenting code on this blog. Seeing that there's currently no "brush" for golang, I decided to create one. I posted the code here for anyone interested. To use it, simply put the following line where you'd normally do it for SyntaxHighlighter brushes (usually before the <head> tag):
<script src='https://raw.github.com/axx/GolangHighlighter/master/shBrushGo.js' type='text/javascript'/>
Then use either "go" or "golang" as alias when you insert golang code on your blog:
<pre class="brush: go">package main
import "fmt"
func main() {
    fmt.Printf("yoohoo!")
}</pre>
This will be rendered as:
package main
import "fmt"
func main() {
    fmt.Printf("yoohoo!")
}
I hope someone else finds it useful. Please drop a comment if you have some suggestions on how to improve it.
EDIT (05AUG2012): I've lost my old server so I had to reconstruct the script and placed it on GitHub. I therefore updated the example and links above.

6 comments:

  1. it's out of work. something wrong?

    ReplyDelete
  2. must be something to do with github. i got a popup first that the script isn't working, but now it's back. to be safe, you can simply copy it at put it somewhere on your own server :)

    ReplyDelete
  3. errr... it's really not working anymore. i'll have a look later when i get some free time. thanks for the heads up, xiao.

    ReplyDelete
  4. Hi there, I found your blog by the use of Google whilst searching for a comparable topic, your website came up, it seems to be good. I’ve bookmarked it in my google bookmarks.
    website design

    ReplyDelete