advanced-code-coderay.org

Turns out there’s more way to do code than just BEGIN_EXAMPLE.

1 Inline examples

This should work:

  fixed width? how does this work?   
                        ...........
                       ............
                                  .
                       .  .   .   .
                       .          ..
                       ....... .....
                           .  .
                           ....

Two ASCII blobs.

2 BEGIN_SRC

And this:

# Finds all emphasis matches in a string.
# Supply a block that will get the marker and body as parameters.
def match_all(str)
  str.scan(@org_emphasis_regexp) do |match|
    yield $2, $3
  end
end

Now let’s test case-insensitive code blocks.

# Finds all emphasis matches in a string.
# Supply a block that will get the marker and body as parameters.
def match_all(str)
  str.scan(@org_emphasis_regexp) do |match|
    yield $2, $3
  end
end
(def fib-seq
  (concat
   [0 1]
   ((fn rfib [a b]
        (lazy-cons (+ a b) (rfib b (+ a b)))) 0 1)))
 
user> (take 20 fib-seq)
(0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181)

Even if no language is set, it is still wrapped in code tags but class is empty.

echo 'Defaults env_keeps="http_proxy https_proxy ftp_proxy"' | sudo tee -a /etc/sudoers

3 It should be possible to write a colon at the beginning of an example

I really love to write about :symbols. They sure are the best things in the world!

{
:one => 1,
:two => 2
}
(defproject helloworld "0.1"
:dependencies [[org.clojure/clojure
                 "1.1.0-master-SNAPSHOT"]
              [org.clojure/clojure-contrib
                 "1.0-SNAPSHOT"]]
:main helloworld)

4 Code syntax highlight with Coderay

4.1 No language selected

Nothing to see here

4.2 CSS example

* {
 /* apply a natural box layout model to all elements */
 box-sizing: border-box; 
 -moz-box-sizing: border-box; 
 -webkit-box-sizing: border-box; 
}

4.3 HTML example

<html>
  <head>
    <title>Hello</title>
  </head>
  <body>
    <h1>Hello</h1>
  </body>
</html>

4.4 Ruby example

class Post << ActiveRecord::Base
  def print_title
    puts "#{self.title}"
  end
end

4.5 Python example

import mapnik

m = mapnik.Map(600, 800)
m.background = Map.Color('steelblue')

4.6 Javascript example

exports = this;

(function($){

var Posts = {};

Posts.index = function(){
// TODO
};

})(jQuery);

4.7 JSON example

{ name: "Waldemar"
, surname: "Quevedo"
}

4.8 PHP example

echo "Hello";
phpinfo();
var_dump(some_var);

4.9 Elisp example

(defun hello()
  (interactive)
  (message "hello"))

4.10 Not supported language example

!+!+++!++!++!++!+