File: advanced-code-pygments.org

package info (click to toggle)
ruby-org 0.9.12-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,852 kB
  • sloc: ruby: 3,044; lisp: 50; makefile: 4
file content (202 lines) | stat: -rw-r--r-- 3,943 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#+TITLE:     advanced-code.org
#+AUTHOR:    Brian Dewey
#+EMAIL:     bdewey@gmail.com
#+DATE:      2009-12-30 Wed
#+DESCRIPTION: More types of code support
#+KEYWORDS: 
#+LANGUAGE:  en
#+OPTIONS:   H:3 num:t toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
#+OPTIONS:   TeX:t LaTeX:nil skip:nil d:nil todo:t pri:nil tags:not-in-toc
#+INFOJS_OPT: view:nil toc:nil ltoc:t mouse:underline buttons:0 path:http://orgmode.org/org-info.js
#+EXPORT_SELECT_TAGS: export
#+EXPORT_EXCLUDE_TAGS: noexport
#+LINK_UP:   
#+LINK_HOME: 

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

* Inline examples

This should work:

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

Two ASCII blobs.

* BEGIN_SRC
:PROPERTIES:
:ARCHIVE_TIME: 2009-12-26 Sat 22:16
:ARCHIVE_FILE: ~/brians-brain/content/projects/orgmode_parser.org
:ARCHIVE_OLPATH: &lt;%= @page.title %&gt;/Future Development
:ARCHIVE_CATEGORY: orgmode_parser
:ARCHIVE_TODO: DONE
:END:

And this:

#+BEGIN_SRC ruby
    # 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
#+END_SRC

Now let's test case-insensitive code blocks.

#+begin_src ruby
    # 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
#+end_src

#+begin_src clojure
(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)
#+end_src

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

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

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

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

#+BEGIN_SRC ruby
{
:one => 1,
:two => 2
}
#+END_SRC

#+BEGIN_SRC clojure
(defproject helloworld "0.1"
:dependencies [[org.clojure/clojure
                 "1.1.0-master-SNAPSHOT"]
              [org.clojure/clojure-contrib
                 "1.0-SNAPSHOT"]]
:main helloworld)
#+END_SRC
* Code syntax highlight with Pygments

** No language selected

#+BEGIN_SRC          
<script>alert('hello world')</script>
#+END_SRC

** CSS example

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

** HTML example

#+BEGIN_SRC html
<html>
  <head>
    <title>Hello</title>
  </head>
  <body>
    <h1>Hello</h1>
  </body>
</html>
#+END_SRC

** Ruby example

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

** Python example

#+BEGIN_SRC python
import mapnik

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

** Javascript example

#+BEGIN_SRC javascript
exports = this;

(function($){

var Posts = {};

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

})(jQuery);
#+END_SRC

** JSON example

#+BEGIN_SRC json
{ name: "Waldemar"
, surname: "Quevedo"
}
#+END_SRC

** PHP example

#+BEGIN_SRC php
echo "Hello";
phpinfo();
var_dump(some_var);
#+END_SRC

** Elisp example

#+BEGIN_SRC emacs-lisp
(defun hello()
  (interactive)
  (message "hello"))
#+END_SRC

** Not supported language example

#+BEGIN_SRC notsupported
!+!+++!++!++!++!+
#+END_SRC