Inserting Pretty Code

We are programmers. Like all good programmers, we like to insert code snippets into our items for our documentation, how-to articles and launch.pad blog entries. We go about this one of two ways these days. Markdown editor or gist snippet.

We are programmers. Like all good programmers, we like to insert code snippets into our items for our documentation, how-to articles and launch.pad blog entries. We go about this one of two ways these days. Markdown editor or gist snippet.

Without question, the most common one we use is markdown code, so lets look at an example:

By inserting this in a markdown content entry …

~~~~ruby  
def hello  
  "Hello World"  
end  
~~~~  

you will get ….

1def hello
2  "Hello World"
3end

Pretty neat eh? What happens is that on saving your content, it is parsed with coderay to produce the nicely highlighted code snippet. All you need to do is to specify what language highlighter to use. In this example, I used ruby, but it could have easily been javascript or some other language snippet.

So what about gists?

Inserting a gist in a snippet is pretty easy. Adding {{ '12345' | gist }} to your snippet will do the trick of inserting gist id 12345 into your html.

We’ve shown you that before right here but you can just add in github’s embed script straight from your gist. It works just as good.

by Craig Sullivan
launch.ly

2 Nov 2012