File: code-block-exports-pygments.html

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 (165 lines) | stat: -rw-r--r-- 6,087 bytes parent folder | download | duplicates (3)
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>#+begin_src ruby :results output :exports both
puts &quot;Hello world&quot;
#+end_src

#+RESULTS:
: 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>#+begin_src python :results output :exports both
print &quot;like&quot;
print &quot;this&quot;
print &quot;etc...&quot;
#+end_src

#+RESULTS:
: like
: this
: etc...
</pre></div>
  </li>
  <li>As an example code block.
<div class="highlight"><pre>#+begin_src ruby :results output :exports both
10.times {|n| puts n }
#+end_src

#+RESULTS:
#+begin_example
0
1
2
3
4
5
6
7
8
9
#+end_example
</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>#+begin_src ruby :results output code
counter = 0
10.times { puts &quot;puts &#39;#{counter += 1}&#39;&quot; } # Displayed in first code block
puts counter # Displayed in second code block
#+end_src

#+RESULTS:
#+begin_src ruby
puts &#39;1&#39;
puts &#39;2&#39;
puts &#39;3&#39;
puts &#39;4&#39;
puts &#39;5&#39;
puts &#39;6&#39;
puts &#39;7&#39;
puts &#39;8&#39;
puts &#39;9&#39;
puts &#39;10&#39;
10
#+end_src

#+RESULTS:
: 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 class="p">(</span><span class="nf">message</span> <span class="s">&quot;hello world&quot;</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 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="k">print</span> <span class="s">&quot;import this&quot;</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 class="kd">var</span> <span class="nx">message</span> <span class="o">=</span> <span class="s2">&quot;Hello world!&quot;</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 class="kd">var</span> <span class="nx">message</span> <span class="o">=</span> <span class="s2">&quot;Hello world!&quot;</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span><span class="o">&lt;</span> <span class="mi">10</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</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>
<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 class="no">Math</span><span class="o">::</span><span class="no">PI</span> <span class="o">+</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 class="n">hello</span> <span class="o">=</span> <span class="o">&lt;&lt;</span><span class="no">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="no">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&#8217;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>