/spec/html_code_syntax_highlight_examples/code-block-exports-pygments.html
HTML | 165 lines | 159 code | 6 blank | 0 comment | 0 complexity | ed670de6017eaa3e10ed62023d5ea53b MD5 | raw file
- <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>#+begin_src ruby :results output :exports both
- puts "Hello world"
- #+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><span></span>#+begin_src python :results output :exports both
- print "like"
- print "this"
- print "etc..."
- #+end_src
- #+RESULTS:
- : like
- : this
- : etc...
- </pre></div>
- </li>
- <li>As an example code block.
- <div class="highlight"><pre><span></span>#+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><span></span>#+begin_src ruby :results output code
- counter = 0
- 10.times { puts "puts '#{counter += 1}'" } # Displayed in first code block
- puts counter # Displayed in second code block
- #+end_src
- #+RESULTS:
- #+begin_src ruby
- puts '1'
- puts '2'
- puts '3'
- puts '4'
- puts '5'
- puts '6'
- puts '7'
- puts '8'
- puts '9'
- puts '10'
- 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></span><span class="p">(</span><span class="nf">message</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="k">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="nx">message</span> <span class="o">=</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="nx">message</span> <span class="o">=</span> <span class="s2">"Hello world!"</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"><</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></span><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></span><span class="n">hello</span> <span class="o">=</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>