forked from bdewey/org-ruby
-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathcode-block-exports-pygments.html
More file actions
165 lines (159 loc) · 6.92 KB
/
code-block-exports-pygments.html
File metadata and controls
165 lines (159 loc) · 6.92 KB
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
<h1 class="title">Support for :exports options from code blocks</h1>
<p>According to the <a href="http://orgmode.org/manual/Exporting-code-blocks.html#Exporting-code-blocks">Org mode docs</a>, it is possible to customize whether
the code block will be exported or not.</p>
<h1>About the <code>#+RESULTS:</code> block</h1>
<p>Using Org Babel features, it is possible to set <code>:results output</code>
to a code block and render the results within a <code>#+RESULTS:</code> code block:</p>
<div class="highlight"><pre><span></span><span class="ow">#+begin_src ruby :results output :exports both</span>
puts "Hello world"
<span class="ow">#+end_src</span>
<span class="nn">#+RESULTS:</span>
: Hello world
</pre></div>
<p>One thing about the <code>#+RESULTS:</code> code blocks, is that they exist in several forms:</p>
<ol>
<li>As an accumulated group of inline examples:
<div class="highlight"><pre><span></span><span class="ow">#+begin_src python :results output :exports both</span>
print "like"
print "this"
print "etc..."
<span class="ow">#+end_src</span>
<span class="nn">#+RESULTS:</span>
: like
: this
: etc...
</pre></div>
</li>
<li>As an example code block.
<div class="highlight"><pre><span></span><span class="ow">#+begin_src ruby :results output :exports both</span>
10.times {|n| puts n }
<span class="ow">#+end_src</span>
<span class="nn">#+RESULTS:</span>
<span class="ow">#+begin_example</span>
0
1
2
3
4
5
6
7
8
9
<span class="ow">#+end_example</span>
</pre></div>
</li>
<li>Also, in case <code>:results output code</code> is used, the results would
be a src block of the same language as the original one.
<div class="highlight"><pre><span></span><span class="ow">#+begin_src ruby :results output code</span>
counter = 0
10.times { puts "puts '#{counter += 1}'" } # Displayed in first code block
puts counter # Displayed in second code block
<span class="ow">#+end_src</span>
<span class="nn">#+RESULTS:</span>
<span class="ow">#+begin_src ruby</span>
puts '1'
puts '2'
puts '3'
puts '4'
puts '5'
puts '6'
puts '7'
puts '8'
puts '9'
puts '10'
10
<span class="ow">#+end_src</span>
<span class="nn">#+RESULTS:</span>
: 10
</pre></div>
</li>
</ol>
<h1>Default options</h1>
<p>The default is to export only the code blocks.</p>
<p>The following is an code block written in Emacs Lisp
and its result should not be exported.</p>
<div class="highlight"><pre><span></span><span class="p">(</span><span class="nf">message</span><span class="w"> </span><span class="s">"hello world"</span><span class="p">)</span>
</pre></div>
<p>The following is a code block written in Python
and its result should not be exported.</p>
<div class="highlight"><pre><span></span><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">12</span><span class="p">):</span>
<span class="nb">print</span> <span class="s2">"import this"</span>
</pre></div>
<p>
</p>
<h1>:exports code</h1>
<p>Only the code would be in the output,
the same as when no option is set.</p>
<div class="highlight"><pre><span></span><span class="kd">var</span><span class="w"> </span><span class="nx">message</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Hello world!"</span><span class="p">;</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">message</span><span class="p">);</span>
</pre></div>
<p>And as block example too:</p>
<div class="highlight"><pre><span></span><span class="kd">var</span><span class="w"> </span><span class="nx">message</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Hello world!"</span><span class="p">;</span>
<span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kd">var</span><span class="w"> </span><span class="nx">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mf">0</span><span class="p">;</span><span class="w"> </span><span class="nx">i</span><span class="o"><</span><span class="w"> </span><span class="mf">10</span><span class="p">;</span><span class="w"> </span><span class="nx">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">message</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
<p>
</p>
<h1>:exports none</h1>
<p>This omits both the resulting block,
and the code block itself.</p>
<p>This should work as well when using an example block.</p>
<p>
</p>
<h1>:exports both</h1>
<div class="highlight"><pre><span></span><span class="no">Math</span><span class="o">::</span><span class="no">PI</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span>
</pre></div>
<pre class="example">
4.14159265358979
</pre>
<p>Should behave the same when within a block example.</p>
<div class="highlight"><pre><span></span><span class="n">hello</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o"><<</span><span class="dl">HELLO</span>
<span class="sh">The following is a text</span>
<span class="sh">that will contain at least 10 lines or more</span>
<span class="sh">so that when C-c C-c is pressed</span>
<span class="sh">and Emacs lisp</span>
<span class="sh">evals what is inside of the block,</span>
<span class="sh">enough lines would be created</span>
<span class="sh">such that an example block </span>
<span class="sh">would appear underneath the</span>
<span class="sh">block that was executed.</span>
<span class="sh">This happens after 10 lines by default.</span>
<span class="dl">HELLO</span>
</pre></div>
<pre class="example">
The following is a text
that will contain at least 10 lines or more
so that when C-c C-c is pressed
and Emacs lisp
evals what is inside of the block,
enough lines would be created
such that an example block
would appear underneath the
block that was executed.
This happens after 10 lines by default.
</pre>
<h1>:exports results</h1>
<p>This option can’t be completely supported by OrgRuby since
we would have to eval the code block using :lang,
so Org Babel features would have to be implemented as well.</p>
<p>But in case the resulting block is within the Org mode file,
the code block will be omitted and only the results block
would appear.</p>
<pre class="example">
3.141592653589793
</pre>
<p>The same should happen when a block example is used instead:</p>
<pre class="example">
any string
any string
any string
any string
any string
any string
any string
any string
any string
any string
</pre>